typescript - 使用 Microsoft Teams 机器人进行频道和群聊对话
问题描述
目前正在使用 Watson Assistant,我的新项目是将其与 Microsoft Teams 集成。它已经在 1 对 1 对话中起作用,但我不知道如何让它在频道或群组中回答。我是打字稿的新手,所以我还不了解大部分内容。有什么想法或提示可以帮助我实现这一点吗?当我寻求帮助时,我被告知尝试使用下面链接的信息在此处实施它。
public async handleMessage(context: TurnContext) {
let dialogResult: DialogTurnResult;
const dc: DialogContext = await this.dialogs.createContext(context);
let ibmWatsonContextId = await this.ibmWatsonContextId.get(context, null);
if (ibmWatsonContextId === null) {
ibmWatsonContextId = await this.retrieveAndSetIBMWatsonContextID(context);
}
// you can use the user in this function or any other dialog by passing the state property accessor
// on local system, user won't be set automatically. so anonymous
const user = await this.userData.get(context, {
firstname: "anonymous",
lastname: "anonymous",
email: "anonymous.anonymous@siemens.com",
gid: "xxxxxxxx",
department: "anonymous"
});
let response: MessageResponse;
let topIntent: string;
if (!dc.activeDialog || dc.activeDialog.id !== OptionsDialog.DIALOG_NAME) {
response = await this.getConversationResponse(context.activity.text, context, ibmWatsonContextId)
topIntent = await this.getTopIntent(response);
const interrupted = await this.isTurnInterrupted(dc, topIntent);
if (interrupted) {
if (dc.activeDialog !== undefined) {
// issue a re-prompt on the active dialog
await dc.repromptDialog();
} // Else: We dont have an active dialog so nothing to continue here.
}
}
dialogResult = await dc.continueDialog();
if (typeof dialogResult.result === "object" && dialogResult.result.rerunNLU) {
response = await this.getConversationResponse(dialogResult.result.result, context, ibmWatsonContextId);
topIntent = await this.getTopIntent(response);
}
// If no active dialog or no active dialog has responded,
if (!dc.context.responded) {
// Switch on return results from any active dialog.
switch (dialogResult.status) {
// dc.continueDialog() returns DialogTurnStatus.empty if there are no active dialogs
case DialogTurnStatus.empty:
if (this.intentSet.has(topIntent)) {
await dc.beginDialog(topIntent);
}
case DialogTurnStatus.complete:
// The dialog has completed, but we haven't given the user any response. Maybe we want to send a default answer here?
if (!this.intentSet.has(topIntent)) {
for (let messageResponse of response.output.generic) {
await this.nluResponseHandler.handle(dc, messageResponse);
}
}
break;
case DialogTurnStatus.waiting:
// The active dialog is waiting for a response from the user, so do nothing.
break;
// All child dialogs have ended. so do nothing.
break;
default:
// Unrecognized status from child dialog. Cancel all dialogs.
await dc.cancelAllDialogs();
break;
}
}
await this.userState.saveChanges(context);
await this.conversationState.saveChanges(context);
}
如果需要更多代码,我将不得不请求许可。提前致谢,
解决方案
推荐阅读
- c++ - 如何创建跨多个目录查找文件并将目标文件放入不同目录的 Makefile?
- javascript - 导入的嵌套模块提供程序取决于顶层模块
- typescript - 在 Google Action 中清除对话会话参数
- dm-script - 如何创建 3D 图像,其中每个平面都分配给单个图像而无需迭代
- matplotlib - 获取 matplotlib 图的高度和宽度时的竞争条件
- kotlin - 我正在尝试为我的最终项目制作 F1 排名应用程序,但找不到正确实施它的方法
- c# - 我在 Windows 窗体中有两个 ListView,我想从第一个列表视图中进行选择,出现在第二个列表视图中
- json - 用于全局变异子索引模式的 Logstash 配置
- selenium - 无法在站点中切换元素(引导程序)
- mysql - 除了id,如何在strapi中设置主键?