Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird error with Facebook Messenger Platform/bot Welcome Confugration

I'm getting a weird error while configuring welcome message for my Messenger bot. I've been using the same code (as shown below) and it has just been working fine until last night. I tried it with both cURL and Postman. Neither of them works.

curl -X POST -H "Content-Type: application/json" -d '{
  "setting_type":"call_to_actions",
  "thread_state":"new_thread",
  "call_to_actions":[
    {
      "message":{
        "text":"Welcome to My Company!"
      }
    }
  ]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"

Error message when executing the code above:

{"error":{"message":"(#100) Invalid keys \"message\" were found in param \"call_to_actions[0]\".","type":"OAuthException","code":100,"fbtrace_id":"Hn42Wa+hapI"}}%

I can confirm both PAGE_ID and PAGE_ACCESS_TOKEN are correct as trying to delete the welcome message with the following code works fine.

curl -X POST -H "Content-Type: application/json" -d '{
  "setting_type":"call_to_actions",
  "thread_state":"new_thread",
  "call_to_actions":[
    {
      "message":{
        "text":"Welcome to My Company!"
      }
    }
  ]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"

Also, the code I'm using is exactly the same as shown on the Facebook official API doc. I don't understand why it's saying "message" is not a valid key. Is anyone experiencing the same problem? Did Facebook change their api?

Any help will be much appreciated!

like image 353
lei he Avatar asked Jun 29 '16 16:06

lei he


People also ask

What is Messenger bot app?

A Facebook Messenger bot is a chatbot that lives within Facebook Messenger, meaning it converses with some of the 1.3 billion people who use Facebook Messenger every month. Chatbots can be programmed to understand questions, provide answers, and execute tasks.

How do I check my Messenger bot?

Once you are into the Messenger channel, go to Linked bot and select the chatbot you want to test from the dropdown. Click on Linked bot, then on Confirm.


3 Answers

The docs are now updated, you need to define your payload in payload parameter now (a UTF-8 encoded string), eg:

"call_to_actions":[
    {
      "payload":"USER_DEFINED_PAYLOAD"
    }
]
like image 94
Sahil Mittal Avatar answered Oct 10 '22 09:10

Sahil Mittal


Docs updated:

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

Example:

curl -X POST -H "Content-Type: application/json" -d '{
  "setting_type":"greeting",
  "greeting":{
    "text":"Welcome to My Company!"
  }
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
like image 28
Ladislau Avatar answered Oct 10 '22 09:10

Ladislau


I get the same issue and fix it. I think your json of request is

let messageData = {
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
  {
    "payload":"welcome_payload"
  }
]
}
request({
    url: 'https://graph.facebook.com/v2.6/me/thread_settings',
    qs: {access_token:token},
    method: 'POST',
    json: {
        messageData
    }
}

but it will not work and log will say you have no "setting_type" = =a try this one

  request({
        url: 'https://graph.facebook.com/v2.6/me/thread_settings',
        qs: {access_token:token},
        method: 'POST',
        json: {
            setting_type:"call_to_actions",
            thread_state:"new_thread",
             call_to_actions:[
              {
                "payload":"welcome_payload"
              }
             ]
        }
    }

it work for me.

like image 40
Ymow Wu Avatar answered Oct 10 '22 10:10

Ymow Wu