2017-01-23 120 views
0

我在js中構建了我的第一個messenger bot,並且已經可以接收和回覆郵件併發送帶有選項的卡片,但是我已經嘗試了所有設置一個開始按鈕但沒有成功...這是我所做的:Facebook messenger bot入門按鈕

我不知道我做錯了什麼或我在哪裏必須調用facebookthreadAPI函數。需要建議。從index.js

摘錄:從

function facebookThreadAPI(jsonFile, cmd){ 
// Start the request 
request({ 
    url: 'https://graph.facebook.com/v2.6/me/thread_settings?access_token='+process.env.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-GET-開始-button.json:

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

回答

1

Facebook現在提供了一個新的API來設置與許多其他功能,如問候文本和持久性菜單,所以,而不是使用舊的thread_setting API使用信使配置文件的開始按鈕API。例如使用curl

curl -X POST -H "Content-Type: application/json" -d '{ 
     "get_started":{ 
     "payload":"GET_STARTED_PAYLOAD" 
    } 
    }' "https://graph.facebook.com/v2.6/me/messenger_profileaccess_token=PAGE_ACCESS_TOKEN"  

與你的頁面訪問令牌和GET_STARTED_PAYLOAD你想要的任何有效載荷替換PAGE_ACCESS_TOKEN。 請參閱完整tutorial here

0

我有同樣的問題。 Here你可以找到文件。

我試圖執行沒有結果的例子。

捲曲-X POST -H 「內容類型:應用/ JSON」 -d「{ 「setting_type」: 「call_to_actions」, 「thread_state」: 「new_thread」, 「call_to_actions」:[ { 「有效載荷」: 「USER_DEFINED_PAYLOAD」 } ] } 「」 https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN

我的錯誤是:

需要pages_messaging權限才能管理對象

但我的頁面未公開。

編輯:你可以找到解決方案Here。它不起作用的頁面管理員

0

現在,隨着新的API,我正在嘗試設置GetStarted按鈕這一要求:curl -X POST -H "Content-Type: application/json" -d '{ "get_started":{ "payload":"start"} }' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=My_Token" 並獲得{"result":"success"}。但該按鈕仍然不會出現在聊天中。所以,我還是不明白,這裏有什麼問題...