[英]Is it possible to send a message to the Bot Framework as if it were from the user?
[英]Send message to bot on click of menu item bot framework
单击Microsoft boframework网络聊天中的静态菜单项时,我很难向bot发送消息。 我修改了顶部导航,并具有静态菜单项,并且在单击任何菜单项时,都应将文本作为消息发送给bot。
我阅读了Microsoft文档,发现我们需要发布直接行,以便将消息发送给bot。 请参阅https://docs.microsoft.com/zh-CN/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-服务4.0
我想知道是否还有其他选择,因为我无法正确制作api并在单击项目时调用。
MenuItemClick(event) {
console.log(event.target.innerText);
Needle('post','https://directline.botframework.com/v3/directline/conversations', headers, {});
}
我期望在单击菜单项时,与菜单项关联的文本应作为消息进入机器人。
我假设您正在最小化Web聊天示例的基础上构建。 我建议不要从Direct Line发送消息以发送消息,而建议从Web Chat的商店中调度sendMessage
操作。 大多数逻辑已经为您服务。 您只需要从Web Chat Core导入sendAction
方法并定义handleMenuItemClick
函数即可。 看一下下面的代码片段。
最小化的Web聊天示例
...
// Import `sendMessage` actiion from Web Chat Core
import sendMessage from 'botframework-webchat-core/lib/actions/sendMessage';
...
export default class extends React.Component {
constructor(props) {
super(props);
...
// bind `handleMenuItemClick` to component
this.handleMenuItemClick = this.handleMenuItemClick.bind(this);
...
}
// add `handleMenuItemClick` to component
handleMenuItemClick({ target: { innerText }}) {
const { store: { dispatch }} = this.state;
dispatch(sendMessage(innerText));
}
render() {
const { state: {
minimized,
newMessage,
side,
store,
styleSet,
token
} } = this;
return (
<div className="minimizable-web-chat">
...
</div>
}
}
屏幕截图
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.