确定在Gupshup上构建的facebook bot的Carousel中单击的按钮

时间:2017-07-10 10:27:18

标签: chatbot gupshup

我正在使用Gupshup.io在Facebook上构建我的机器人,我对旋转木马有疑问。

假设我在旋转木马上有4个项目,每个项目都有一个购买按钮,那么我怎么知道用户在旋转木马中点击了哪个项目的按钮?

1 个答案:

答案 0 :(得分:3)

当用户点击轮播中的按钮时,发送回机器人的响应包括按钮名称和该列表中项目的位置。

例如:

在下图中,如果用户点击白色T恤的购买按钮,则机器人会收到响应为" 买1 "对于灰色T恤,机器人将收到响应" 买2 "。有关详细信息,请参阅此guide enter image description here

Gupshup的IDE Bot Builder的完整示例代码:

if(event.message=='t-shirt'){
       var catalogue = {
          "type": "catalogue",
          "imageaspectratio": "horizontal",
          "msgid": "cat_212",
          "items": [
            {
              "title": "White T Shirt",
             "subtitle": "Soft cotton t-shirt \nXs, S, M, L \n$10",
              "imgurl": "http://petersapparel.parseapp.com/img/item100-thumb.png",
              "options":[
                {
                  "type":"url",
                  "title":"View Details",
                  "url":"http://petersapparel.parseapp.com/img/item100-thumb.png"
                },
                 {
                  "type":"text",
                  "title":"Buy"
                 }
               ]
            },
            {
              "title": "Grey T Shirt",
              "subtitle": "Soft cotton t-shirt \nXs, S, M, L \n$12",
              "imgurl": "http://petersapparel.parseapp.com/img/item101-thumb.png",
              "options":[
                {
                  "type":"url",
                  "title":"View Details",
                  "url":"http://petersapparel.parseapp.com/img/item101-thumb.png"
                },
                 {
                  "type":"text",
                  "title":"Buy"
                 }
                ]
              }
            ]
         };
    context.sendResponse(JSON.stringify(catalogue));
    return;
       }
    if(event.message=='Buy 1' && event.messageobj.refmsgid=='cat_212'){
      context.sendResponse("Your white t-shirt will be shipped within 1 working day.");
     return;
    }
  if(event.message=='Buy 2' && event.messageobj.refmsgid=='cat_212'){
      context.sendResponse("Your Grey t-shirt will be shipped within 1 working day.");
     return;
    }