facebook messenger and dialogflow:: detect each event individually from multiple generic templates button

隐身守侯 提交于 2021-01-29 13:19:56

问题


I am working with chatbot and dialogflow is my nlp platform. Currently, I am using generic templates to show my products on messenger.

Now, when customer clicks on buy now button from multiple templates buttons I want to detect which template button has been clicked (detect individual event) and want to set different message for different product from dialogflow.

One way to do the job is using context but I want to know whether it is possible to achieve the same outcome without using context or not?

Any suggestion will be appreciated. Thanks!


回答1:


You can use the payload field in the postback button to send a specific message back to dialogflow when the button is clicked.

If you combine this with the parameters, you can use them to trigger specific intents, or just to send the information of the product clicked. For example:

Imagine an intent with the following phrases:

In this case: "toaster" and "microwave" are part of an entity called objects

In the response to messenger, you can include reference to this parameter, for example:

{
  "facebook": {
    "attachment": {
      "type": "template",
      "payload": {
        "template_type": "button",
        "buttons": [
          {
            "payload": "trigger buy $objects",
            "title": "Buy Now",
            "type": "postback"
          }
        ],
        "text": "Buy the $objects!"
      }
    }
  }
}

Which will show the parameter:

When the user clicks on the button, messenger will send dialogflow the content of the payload, in this case: "trigger buy toaster". Note that in the payload the reference $objects is also replaced by the actual parameter "toaster".

So you can create a new intent in Dialogflow with training phrases as "trigger buy toaster" to catch these actions with the object that is going to be purchased.

You can also use the webhook fulfillment to add more logic to the generation of the postback button responses and to the intent that receives the answer.



来源:https://stackoverflow.com/questions/64858414/facebook-messenger-and-dialogflow-detect-each-event-individually-from-multiple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!