1

我正在使用 Gupshup.io 在 Facebook 上构建我的机器人,我对轮播有疑问。

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

4

1 回答 1

3

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

例如:

在下图中,如果用户单击白色 T 恤的购买按钮,则机器人将收到“购买 1 ”的响应,而对于灰色 T 恤,机器人将收到“购买 2 ”的响应。有关更多详细信息,请参阅本指南 在此处输入图像描述

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;
    }
于 2017-07-11T10:13:36.043 回答