0

我正在使用 Gupshup,我想在我的聊天中添加子视图。为此,我创建了这个变量:

var url="https://api.gupshup.io/sm/api/facebook/smartmsg/form/create";
var header = {"apikey":"xxxxxxxxxxxxxxxxxxx","Content-Type": "application/x-www-form-urlencoded","Accept":"application/json"};
var param={"formJSON":{
    "title": "This is a test.",
    "autoClose": false,
    "message": "Thank You",
    "callback-url": "https://www.gupshup.io/developer/bot/Cotizador/public",
    "fields": [{
        "type": "fbid",
        "name": "fbname",
        "label": "fbName"
    }, {
        "type": "input",
        "name": "name",
        "label": "Name",
        "validations": [{
            "regex": "^[A-Z a-z]+$",
            "msg": "Only alphabets are allowed in this field"
        }, {
            "regex": "^[A-Z a-z]{6,}$",
            "msg": "Minimum 6 characters required"
        }]
    }, {
        "type": "radio",
        "name": "gender",
        "label": "Gender",
        "options": [
            "Male",
            "Female"
        ],
        "validations": [{
            "regex": "",
            "msg": ""
        }]
    }, {
        "type": "select",
        "name": "account",
        "label": "AccountType",
        "options": [
            "current",
            "savings"
        ],
        "validations": [{
            "regex": "",
            "msg": ""
        }]
    }, {
        "type": "checkbox",
        "name": "interest",
        "label": "Interests",
        "options": [
            "Cooking",
            "Reading"
        ],
        "validations": [{
            "regex": "",
            "msg": ""
        }]
    }],
    "users": [
        "Testing"
    ]
}}

并通过以下方式致电发布:

context.simplehttp.makePost(url,JSON.stringify(param),header,parser);

我的回电

function parser(context, event) {
     context.console.log("Handler https")
           var result= JSON.parse(event.getresp);
        if(result=="success"){
       context.sendResponse("We have successfully stored your data");
       }else{
              context.sendResponse("We dont shoot");
       }
}

但是,何时发布请求,但不要在聊天或回调中显示回复。我做错了什么?

4

1 回答 1

2

来自 Gupshup 的 Sohan。您使用的 API 的结果是这样的:

[{
    "embedlink": "https://api.gupshup.io/sm/api/facebook/smartmsg/embed/66438dde-ec76-4d6e-a0d0-8cfc0c730e57",
    "expired": false,
    "fb-button": {
        "title": "This is a test.",
        "type": "web_url",
        "url": "https://api.gupshup.io/sm/api/facebook/smartmsg/embed/66438dde-ec76-4d6e-a0d0-8cfc0c730e57",
        "webview_height_ratio": "tall"
    },
    "id": "66438dde-ec76-4d6e-a0d0-8cfc0c730e57",
    "signed-for": {
        "display": "Testing",
        "subdisplay": "Testing"
    },
    "smid": "1009"
}]

因此,当您这样做时:

var result= JSON.parse(event.getresp);
   if(result=="success"){

context.sendResponse(result) 将显示您在上面看到的整个 JSON。要显示“过期”字段,您可以使用result.expired.

查看此文档以获取更多信息。

于 2017-07-19T09:46:16.563 回答