首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gupshup使用post创建嵌入表单

Gupshup使用post创建嵌入表单
EN

Stack Overflow用户
提问于 2017-07-18 15:06:32
回答 1查看 138关注 0票数 0

我和Gupshup一起工作,我想在我的聊天中添加子视图。为了做到这一点,我创建了这个vars:

代码语言:javascript
复制
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),标头,解析器);

然后我回电话

代码语言:javascript
复制
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");
       }
}

但是什么时候,发出请求帖子,但不要在聊天或回调中显示我的响应。我做错什么了?

EN

回答 1

Stack Overflow用户

发布于 2017-07-19 09:46:16

从古普舒来的。您正在使用的API的结果是:

代码语言:javascript
复制
[{
    "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"
}]

因此,当你这样做时:

代码语言:javascript
复制
var result= JSON.parse(event.getresp);
   if(result=="success"){

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

有关更多信息,请查看本文件

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45170608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档