0

im working with Gupshup and I want to add subview in my chat. To make this I create this vars:

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"
    ]
}}

And call post with:

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

And my call back

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");
       }
}

But when, make the request post, but don't show me response in chat or in callback. What im doing wrong?

Daniel ORTIZ
  • 2,488
  • 3
  • 21
  • 41

1 Answers1

2

Sohan from Gupshup here. The result from the API that you are using is this:

[{
    "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"
}]

Thus when you do:

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

context.sendResponse(result) will display the entire JSON that you see above. To display the 'expired' field you can use result.expired.

Check this document for more information.

Sohan
  • 1,287
  • 1
  • 15
  • 29