【问题标题】:"Get Started" button on facebook bot with bot framework带有 bot 框架的 facebook bot 上的“开始”按钮
【发布时间】:2016-12-21 04:06:24
【问题描述】:

如何在 facebook bots 中将开始按钮与同一个按钮放在一起?我检查了 facebook 文档,它说我必须打电话给 facebook 服务,但我没有搞定。这是文档 URL。

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

【问题讨论】:

    标签: node.js botframework


    【解决方案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-greeting-text.json

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

    fb-get-started-button.json

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

    fb-persistent-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"
        }
      ]
    }
    

    【讨论】:

    • 是否可以用c#来做。你能指导我吗?
    猜你喜欢
    • 2017-06-07
    • 2016-10-12
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多