2016-10-16 1 views
1

Я использую этот код для кнопки быстрого ответа в facebook посыльного бота (JavaScript):Быстрого ответ на Facebook мессенджер бот не имеет полезную нагрузку

var message = { 
    "attachment": { 
     "type": "template", 
      "payload": { 
       "template_type": "generic", 
       "elements": [{ 
        "title": "Order a cucumber", 
        "subtitle": "A cucumber", 
        "image_url": "SOME_LINK_HERE", 
        "buttons": [ 
         {"type": "postback", 
         "title": "Order", 
         "payload": "cucumber"}, 
         {"type": "postback", 
         "title": "Order & Finish", 
         "payload": "cucumberf"} 
        ] 
       }, 
       { 
        "title": "Order a tomato", 
        "subtitle": "A tomato", 
        "image_url": "SOME_LINK_HERE", 
        "buttons": [ 
         {"type": "postback", 
         "title": "Order", 
         "payload": "tomato"}, 
         {"type": "postback", 
         "title": "Order & Finish", 
         "payload": "tomatof"} 
        ] 
       }, 
       { 
        "title": "Order a cake", 
        "subtitle": "A cake", 
        "image_url": "SOME_LINK_HERE", 
        "buttons": [ 
         {"type": "postback", 
         "title": "Order", 
         "payload": "cake"}, 
         {"type": "postback", 
         "title": "Order & Finish", 
         "payload": "cakef"} 
        ] 
       }] 
      } 
    }, 
    "quick_replies": [ 
     {"content_type": "text", 
     "title": "Main menu", 
     "payload": "mainMenu"} 
    ]}; 

Когда я пытаюсь получить полезная нагрузка кнопки быстрого ответа (event.message.quick_reply), она говорит, что она не определена. Но для других полей он возвращает то, что должен (например, поле «seq» или поле «текст». Что я делаю неправильно, и как я могу использовать полезную нагрузку кнопок быстрого ответа?

ответ

1

Код ниже показывает, как получить все то, что пользователь отправил/нажал:

// handle bot's anwser 
$input = json_decode(file_get_contents('php://input'), true); 
$senderId = $input['entry'][0]['messaging'][0]['sender']['id']; 

// gets the text the user sent to you 
$messageText = $input['entry'][0]['messaging'][0]['message']['text']; 

// gets the payload of the button 
$buttonPayLoad = $input['entry'][0]['messaging'][0]['postback']['payload']; 

// gets the payload of the quick replay 
$quickReplyPayLoad = $input['entry'][0]['messaging'][0]['message']['quick_reply']['payload']; 
Смежные вопросы