2017-06-29 4 views
0

「The Guardian」のようなかなり人気のあるボットを見ていましたが、一般的なテンプレート返信を受け取ったときには、 )。 「ガーディアン・ボット」はこれをどのように達成しましたか?クイック返信と一般的なテンプレートをどのように組み合わせましたか? 2つのメッセージが必要です。Facebookメッセンジャープラットフォーム:クイックレスポンスを使用した汎用テンプレート

enter image description here

+0

ボットは、最初に添付ファイルをポストし、メニューにポストします。そう ? –

+0

正確にどのように動作するのですか?それは最初に一般的なテンプレートを送信してから、すばやく返信しますか?しかし、迅速な返答では、タイトルとタイトルを空にする必要があります。 –

+0

だから?彼らはタイトルを指定しました:) –

答えて

1

私はnodejsでボットを実装していると私はそれが簡単にメッセンジャーボットのAPIを呼び出すことが可能messenger-botと呼ばれるノードモジュールを使用しています。 Generic templateQuick repliesmessenger-bot npm

・ホープ、このことができます - ここで

const http = require('http') 
const https = require('https') 
const Bot = require('messenger-bot') 
var bot = new Bot({ 
    token: 'your FB app token', 
    verify: 'VERIFY_TOKEN' 
}) 

bot.on('postback', (payload, reply) => { 
    var postback = payload.postback.payload; 
    if (postback == "yes") { 

     function getQuickReplies() { 
      console.log("in next function"); 
      var quick_list = { 
       "text": "Check the next article?", 
       "quick_replies": [{ 
         "content_type": "text", 
         "title": "More stories", 
         "payload": "more stories" 
        }, 
        { 
         "content_type": "text", 
         "title": "Sport", 
         "payload": "sport" 
        }, 
        { 
         "content_type": "text", 
         "title": "Business", 
         "payload": "business" 
        } 

       ] 
      }; 
      bot.getProfile(payload.sender.id, (err, profile) => { 
       if (err) throw err 
       text = quick_list; 
       bot.sendMessage(payload.sender.id, text) {//this prints quick replies 
        console.log("sending message"); 
       } 
      }); 
     } 

     //calling generic template 

     var generic_temp = "message": { 
      "attachment": { 
       -- - your code-- - 
      } 
     }; //generic template refer - https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template 

     bot.getProfile(payload.sender.id, (err, profile) => { 
      if (err) throw err 
      bot.sendMessage(payload.sender.id, generic_temp) {//this prints generic template 
       console.log("sending message"); 
      } 
     }); 

     //calling the quick replies once the generic template is sent 

     getQuickReplies(); //to avoid async execution issue, we will have to put this in a function. 

    } 
}); 

参照のための私のカスタマイズされたコードです!ハッピーコーディング;)

0

クイック返信には通常、テキスト返信の前にテキストメッセージを送信する 'text'プロパティが付いています。それはあなたのために任意のテンプレートを置き換えることができますが表示されます。たとえば、以下はクイック返信を含む一般的なテンプレートカルーセルのリクエストボディです:

{ 
    "recipient":{ 
    "id":"{{PSID}}" 
    }, 
    "messaging_type": "response", 
    "message":{ 
     "quick_replies": [ 
     { 
     "content_type":"text", 
     "title":"Quick Reply 1", 
     "image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png", 
     "payload":"payload1" 
     }, 
     { 
     "content_type":"text", 
     "title":"Quick Reply 2", 
     "payload":"payload2" 
     } 
    ], 

    "attachment":{ 
     "type":"template", 
     "payload":{ 
     "template_type":"generic", 
     "elements":[ 
      { 
      "title":"This is a generic template", 
      "subtitle":"Plus a subtitle!", 
      "image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png", 
      "buttons":[ 
       { 
       "type":"postback", 
       "title":"Postback Button", 
       "payload":"<POSTBACK_PAYLOAD>" 
       } 
      ]  
      }, 
      { 
      "title":"Another generic template", 
      "subtitle":"Plus a subtitle!", 
      "image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png", 
      "buttons":[ 
       { 
       "type":"postback", 
       "title":"Postback Button", 
       "payload":"<POSTBACK_PAYLOAD>" 
       } 
      ]  
      }, 
      { 
      "title":"And another!", 
      "subtitle":"Plus a subtitle!", 
      "image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png", 
      "buttons":[ 
       { 
       "type":"postback", 
       "title":"Postback Button", 
       "payload":"<POSTBACK_PAYLOAD>" 
       } 
      ]  
      } 
     ] 
     } 
    } 
    } 
} 
関連する問題