【问题标题】:Send message to bot on click of menu item bot framework单击菜单项机器人框架向机器人发送消息
【发布时间】:2019-08-30 02:16:33
【问题描述】:

我在单击 Microsoft boframework 网络聊天中的静态菜单项时向机器人发送消息时遇到了挑战。我已经修改了顶部导航并具有静态菜单项,并在单击任何菜单项时应将文本作为消息发送给机器人。

我阅读了 Microsoft 文档,发现我们需要发布到直接线路,以便向机器人发送消息。请参考https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0

我想知道除此之外是否还有其他选择,因为我无法正确制作 api 并在单击项目时调用。

MenuItemClick(event) {
console.log(event.target.innerText);
Needle('post','https://directline.botframework.com/v3/directline/conversations', headers, {});
}

我希望单击菜单项时,与菜单项关联的文本应作为消息发送给机器人。

【问题讨论】:

    标签: javascript node.js reactjs botframework


    【解决方案1】:

    我假设您是在 Minimizable Web Chat 示例之上构建的。我建议不要向 Direct Line 发送帖子请求以发送消息,而是从 Web Chat 的商店发送 sendMessage 操作。大多数逻辑已经为您准备好了。您只需要从 Web Chat Core 中导入 sendAction 方法并定义一个 handleMenuItemClick 函数。看看下面的代码 sn-ps。

    最小化网络聊天示例

    ...
    // 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>
      }
    }
    
    

    屏幕截图

    希望这会有所帮助!

    【讨论】:

    • 我们一直在摸索以使其正常工作,您为此提供了简单的解决方案。非常感谢您的帮助。
    猜你喜欢
    • 2012-09-21
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 2021-08-19
    • 2019-06-27
    • 2020-04-02
    • 1970-01-01
    • 2015-07-16
    相关资源
    最近更新 更多