我正在使用 NodeJS 构建一个基于 MS 机器人框架的机器人。我想使用 TypeScript + React 构建客户端,但是,我希望能够在用户登录后发送消息。通过在线搜索,我认为我可以使用反向 channel 来做到这一点,如 this 中所述。页。
但是,我想在 React 应用程序中使用它,如所述 here
我可以让 React 应用程序在我的应用程序中工作,但是我还需要集成反向 channel 。
我不明白为什么在每个示例中我们都使用不同的东西。例如,在 React 应用程序中,我们使用 BotChat.Chat
..但在反向 channel 中,我们使用 BotChat.App
..这两者有什么区别?
此外,我将在我的 React 应用程序中使用反向 channel ,我需要声明 BotChannel 并将其传递给 BotChat.App
,这在我们使用 BotChat.Chat
的 React 中如何工作? ?
任何有关这些差异以及如何使用 React 实现反向 channel 的示例或清晰文档将不胜感激。
谢谢。
最佳答案
为了稍后引用聊天,您可以像这样初始化聊天 div:
<div>
<Chat ref={(chat) => {this._chat = chat;}} directLine={{ secret: "<secret>" }} user={{ id: 'user_id', name: 'user_name' }} />
</div>
这里重要的部分是包含 ref 的定义,如下所示:
ref={(chat) => {this._chat = chat;}}
初始化后,您可以稍后通过 this._chat.botConnection
访问 botConnection 并进行 .postActivity()
调用,如下所示:
this._chat.botConnection
.postActivity({ type: "message", value: "hi", from: { id: "me" } })
.subscribe(id => console.log("success"));
关于App和Chat之间的区别,简单地说,App是一个完整的模式,而聊天则被分解得更容易定制。应用程序扩展了聊天功能。
关于reactjs - 将反向 channel 与 React Client - Bot 框架结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52137338/