通用模板和列表模板不起作用

时间:2018-10-24 09:22:34

标签: facebook-messenger-bot

我正在跟踪Facebook Messenger开发QuickStart来创建Node.js项目,并对其进行了改进以快速回复。然后,当我尝试“通用模板”和“列表模板”时,却没有用。

作为以下源代码,当我输入作品“泛型”或“列表”时,使者应使用模板信息来答复我。但是什么也没发生。

	} else if (received_message.text === 'generic') {
		console.log('generic in');
		response = {
						"attachment":{
						  "type":"template",
						  "payload":{
							"template_type":"generic",
							"elements":[
							   {
									"title":"Welcome!",
									"image_url":"http://webapplication120181023051009.azurewebsites.net/colorcar1.jpg",
									"subtitle":"We have the right hat for everyone.",
									"default_action": {
									  "type": "web_url",
									  "url": "https://www.taobao.com/",
									  "messenger_extensions": false,
									  "webview_height_ratio": "tall",
									  "fallback_url": "https://www.taobao.com/"
								},
								"buttons":[
								  {
									"type":"web_url",
									"url":"https://www.taobao.com/",
									"title":"View Website"
								  },{
									"type":"postback",
									"title":"Start Chatting",
									"payload":"DEVELOPER_DEFINED_PAYLOAD"
								  }              
								]      
							  }
							]
						  }
						}
					}
          
  // Sends the response message
  callSendAPI(sender_psid, response);  
  
  
  // Sends response messages via the Send API
function callSendAPI(sender_psid, response) {
  // Construct the message body
  let request_body = {
    "recipient": {
      "id": sender_psid
    },
    "message": response
  }
  
  console.log('PAGE_ACCESS_TOKEN:');
  console.log(PAGE_ACCESS_TOKEN);
  console.log('request body:');
  console.log(request_body);
  
  // Send the HTTP request to the Messenger Platform
  request({
    "uri": "https://graph.facebook.com/v2.6/me/messages?access_token=" + PAGE_ACCESS_TOKEN,
    "qs": { "access_token": PAGE_ACCESS_TOKEN },
    "method": "POST",
    "json": request_body
  }, (err, res, body) => {
    if (!err) {
      console.log('message sent!')
    } else {
      console.error("Unable to send message:" + err);
    }
  }); 
}

1 个答案:

答案 0 :(得分:0)

对不起,我忘了将该网址添加到whiltelist中。