【问题标题】:Gupshup consume post to create Embedding formGupshup 使用帖子创建嵌入表单
【发布时间】:2017-07-18 15:06:32
【问题描述】:

我正在使用 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");
       }
}

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

【问题讨论】:

    标签: facebook post gupshup


    【解决方案1】:

    来自 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

    查看this document了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 2012-06-17
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多