"入门" facebook bot上的按钮与bot框架

时间:2016-10-05 14:00:04

标签: node.js botframework

如何将get get按钮作为facebook机器人中的同一个按钮?我检查了facebook文档,它说我必须打电话给facebook服务,但我没那么好。这是文档URL。

https://developers.facebook.com/docs/messenger-platform/thread-settings

1 个答案:

答案 0 :(得分:1)

在BotBuilder GitHub中查看this issue。以下是该主题的代码:

<强> app.js

var request = require('request');

//=========================================================
// Facebook setup // Run only when need updating.
//=========================================================

// Set FB bot greeting text
facebookThreadAPI('./fb-greeting-text.json', 'Greating Text');
// Set FB bot get started button
facebookThreadAPI('./fb-get-started-button.json', 'Get Started Button');
// Set FB bot persistent menu
facebookThreadAPI('./fb-persistent-menu.json', 'Persistent Menu');

// Calls the Facebook graph api to change various bot settings
function facebookThreadAPI(jsonFile, cmd){
    // Start the request
    request({
        url: 'https://graph.facebook.com/v2.6/me/thread_settings?access_token='+process.env.FB_PAGE_ACCESS_TOKEN,
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        form: require(jsonFile)
    },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            // Print out the response body
            console.log(cmd+": Updated.");
            console.log(body);
        } else { 
            // TODO: Handle errors
            console.log(cmd+": Failed. Need to handle errors.");
            console.log(body);
        }
    });
}

<强> FB-问候-text.json

{
  "setting_type":"greeting",
  "greeting":{  
    "text":"Your greeting text here."
  }
}

<强> FB-GET-开始-button.json

{
  "setting_type":"call_to_actions",
  "thread_state":"new_thread",
  "call_to_actions":[
    {
      "payload":"action?POSTBACKHERE"
    }
  ]
}

<强> FB-持久menu.json

// Just using the menu to do a single button admin reset
{
  "setting_type" : "call_to_actions",
  "thread_state" : "existing_thread",
  "call_to_actions":[
    {
      "type":"postback",
      "title":"Admin Reset",
      "payload":"action?POSTBACKHERE"
    }
  ]
}