单击菜单项bot框架向bot发送消息 [英] Send message to bot on click of menu item bot framework

查看:108
本文介绍了单击菜单项bot框架向bot发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击Microsoft boframework网络聊天中的静态菜单项时,我很难向bot发送消息.我已经修改了顶部导航,并具有静态菜单项,并且在单击任何菜单项时,都应将文本作为消息发送给bot.

I am having a challenge to send message to bot on click of static menu item in Microsoft boframework webchat. I have modified the top nav and have static menu items and on click of any menu item that text should be sent to bot as message.

我阅读了Microsoft文档,发现我们需要发布直接行,以便将消息发送给bot.请参考

I read over the Microsoft documentation and I see that we need to post to direct line so send message to bot. please refer 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并在单击项目时调用.

I am wondering if there is any alternative apart from this as I am not able to make the api properly and invoke on click of item.

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

我希望在单击菜单项时,与菜单项关联的文本应作为消息传递到机器人.

I am expecting on click of the menu item the text associated with menu item should go to the bot as message.

推荐答案

我假设您是在

I'm assuming you are building on top of the Minimizable Web Chat sample. Instead of making a post request to Direct Line to send a message, I would recommend dispatching a sendMessage action from Web Chat's store. Most of the logic is already there for you. You just need to import the sendAction method from Web Chat Core and define a handleMenuItemClick function. Take a look at the code snippets bellow.

最小化的网络聊天示例

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

屏幕截图

希望这会有所帮助!

这篇关于单击菜单项bot框架向bot发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆