अमेरिकन प्लान बॉट js पर, gupshup

वोट
0

मैं async बुला कार्यों के साथ समस्या का समाधान के लिए देख रहा हूँ, विशेष रूप से context.simplehttp.makePost(url, param, header);gupshup एपीआई से। मैं ठोस अनुक्रम में एक से अधिक संदेश भेजने के लिए की जरूरत है।

यहाँ कोड है:

function MessageHandler(context, event) {
if (event.messageobj.type == msg) {
if (Array_CH(hi_array, message)) {
var contextParam = JSON.stringify(event.contextobj);
var url = https://api.gupshup.io/sm/api/bot/ + event.botname + /msg;
var param = context= + contextParam + &message=;
var header = { apikey: b3843dad0a484ad3ca19b5358be6c809, Content-Type: application/x-www-form-urlencoded };
var catalogue;
var button;
var param1;
param = context= + contextParam + &message=Hey.\nContest called The vivid Emotions needs your assessment.\nLook what emotions here. Do you agree?\nOr are your feelings totally different?;
context.simplehttp.makePost(url, param, header);
catalogue = {
            type: catalogue,
            msgid: cat_212,
            items: [
                {
                    title: Design1,
                    subtitle: Quisque consectetur ornare malesuada.\n Nunc dapibus nec felis.,
                    imgurl: http://sv777.ru/images/stati/239465865852987356diz.jpg,
                    options: [
                        {
                            type: url,
                            title: About,
                            url: http://laminat-parket.net/product/room-yasen-dizajn
                        }
                    ]
                },
                {
                    title: Design2,
                    subtitle: Donec purus sem, mollis a fermentum sit amet, pretium sed lectus.\n Ut at mattis purus.,
                    imgurl: http://laminat-parket.net/upload/productions/55794d8198b65.jpg,
                    options: [
                        {
                            type: url,
                            title: About,
                            url: http://laminat-parket.net/product/room-yasen-dizajn
                        }
                    ]
                },
                {
                    title: Design3,
                    subtitle: Proin nec turpis leo.\n Nam metus augue, aliquam vitae laoreet sed, dignissim a risus.,
                    imgurl: http://www.askwallpapers.com/pic/201502/2880x1800/askwallpapers.com-17168.jpg,
                    options: [
                        {
                            type: url,
                            title: About,
                            url: http://laminat-parket.net/product/room-yasen-dizajn
                        }
                    ]
                },
                {
                    title: Design4,
                    subtitle: Phasellus vitae justo sed velit faucibus hendrerit.\n Aenean scelerisque eros ac tortor tincidunt feugiat.,
                    imgurl: http://www.kidsworldstudio.net/wp-content/uploads/2015/11/bunk-bed-plans-for-kids-bedroom-ideas-home-interior-design-3353-loft-bed-for-kids-loft-bed-for-kids1.jpg,
                    options: [
                        {
                            type: url,
                            title: About,
                            url: http://laminat-parket.net/product/room-yasen-dizajn
                        }
                    ]
                },
                {
                    title: Design5,
                    subtitle: Pellentesque risus nibh, porttitor vitae diam ut, facilisis aliquet velit.\n Quisque scelerisque massa urna. ,
                    imgurl: http://www.wallpaper4k.com/download.php?res=interior%2FWP67USXQ.jpg,
                    options: [
                        {
                            type: url,
                            title: About,
                            url: http://laminat-parket.net/product/room-yasen-dizajn
                        }
                    ]
                }
            ]
        };
button = {
            msgid: bt_2,
            type: survey,
            question: Put your Like and change this rating!,
            options: [
                {
                    type: url,
                    title: Yes,
                    url: http://www.wallpaper4k.com/uk/wallpapers/interior%20design/wp67usxq.html,
                    webview_height_ratio: full
                },
                {
                    type: url,
                    title: Add your own project,
                    url: http://www.wallpaper4k.com/uk/wallpapers/interior%20design/wp67usxq.html,
                    webview_height_ratio: full
                },
                {
                    type: text,
                    title: Need own bot?,
                }
            ]
        };
param = context= + contextParam + &message= + JSON.stringify(catalogue);
param1 = context= + contextParam + &message= + JSON.stringify(button);
context.simplehttp.makePost(url, param, header);
context.simplehttp.makePost(url, param1, header);
return;
  }
 }
}

लेकिन संदेशों हर बार यादृच्छिक क्रम में भेज देते हैं।

17/11/2016 को 18:52
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

वोट
1

एक ठोस अनुक्रम आप एक HTTP कॉल होने देना होता है में एक से अधिक संदेश भेजने के लिए यह दूसरी कॉल करने से पहले निष्पादन है खत्म। वहाँ Gupshup के आईडीई का उपयोग कर HTTP कॉल करने, जबकि अतुल्यकालिक व्यवहार को संभालने के लिए दो तरीके हैं -

  1. डिफ़ॉल्ट HttpResponseHandler का प्रयोग करें। यह हैंडलर हर बार HTTP कॉल खत्म के निष्पादन कहा जाता है।

  2. अपनी खुद की कॉलबैक फ़ंक्शन निर्धारित HTTP कॉल कर रहा है। जैसा - context.simplehttp.makePost (यूआरएल, formParams, हेडर, समारोह)

मैं 2 विकल्प का उपयोग कर के रूप में यह आसान एकाधिक HTTP कॉल को संभालने के लिए बनाता है की सिफारिश करेंगे।

# 2 का उपयोग कर होगा एक दृश्य में 3 संदेश भेजने के लिए छद्म कोड -

function MessageHandler(context, event) {
  context.simplehttp.makePost(url, formParams, headers, secondMsg); 
//sending 1st message
}
function secondMsg(event,context){
    context.simplehttp.makePost(url, formParams, headers, thirdMsg); //sending 2nd message
}
function thirdMsg(event,context){
    context.sendResponse("I am the last message");
}

नोट - का उपयोग कर context.sendResponse संदेश भेजता है और जब तक अगले संदेश बॉट द्वारा प्राप्त होता है कोड निष्पादन से बाहर निकलें।

अधिक जानकारी के लिए बाहर की जाँच दस्तावेज़ gupshup.io पर

06/12/2016 को 06:43
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more