Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Why I can not send chat bot notification to my facebook?

Reading this https://developers.facebook.com/docs/messenger-platform/discovery/facebook-chat-plugin/ manual I created Facebook Page and inserted Messenger Chat Plugin Code into my Laravel 9 page, So I can send and recieve messages in chat bot on facebook page and on page of my site. Next I want to send message from laravel app to user in some case, say user has some event we want to notify him about.

I read this example with code :

Send a POST request to the /PAGE-ID/chat_plugin endpoint to customize the welcome screen greeting, color, icon, and more, for your plugin.

Example Request curl -i -X POST "https://graph.facebook.com/v14.0/PAGE-ID/chat_plugin ?welcome_screen_greeting:YOUR-WELCOME-TEXT &theme_color:553399 &entry_point_icon:MESSENGER_ICON &entry_point_label:CHAT

and I make in my control action:

$messageData = [
    "welcome_screen_greeting"=> "welcome to my app",
    "theme_color"=> "553399",
    "messaging_type"=> "welcome_screen_greeting",
    "entry_point_icon"=> "MESSENGER_ICON", 
    "entry_point_label"=> "CHAT", // ?
    "recipient" => [
        "user_ref" => 'NNNNNN',  // That is id of my profile https://www.facebook.com/profile.php?id=NNNNNN
    ],
    "message"   => [
        "text" => "hello, world from the app!",
    ],
];


$ch = curl_init('https://graph.facebook.com/v14.0/PAGE-ID/chat_plugin?access_token=' . config('app.PAGE_ACCESS_TOKEN'));

\Log::info(  varDump($ch, ' -1 BotController  sendTextMessage $ch::') );

as result on my screen I see :

{"success":true}

I am not sure of which command this output is ?

var $ch in log has empty(false) value. I have valid app.PAGE_ACCESS_TOKEN param in .env file. If I hide one of parameters in $messageData I - got error.

But I do not have any chat bot notification in my facebook...

What is wrong ?

Thanks!

0 likes
6 replies
jorgensolli's avatar

From what I understand, the endpoint you are calling is only for customizing the welcome screen greeting when a user opens the chat widget. It has nothing to do with sending messages to user(s).

As the doc states:

Send a POST request to the /PAGE-ID/chat_plugin endpoint to customize the welcome screen greeting, color, icon, and more, for your plugin.

You need to look for the appropriate API endpoint for actually sending messages if that exists.

good luck :)

1 like
jorgensolli's avatar

@mstdmstd That seems right, yes. So you can send a message to a single user.

curl -X POST -H "Content-Type: application/json" -d '{
  "messaging_type": "<MESSAGING_TYPE>",
  "recipient": {
    "user_ref": "<USER_REF>"
  },
  "message": {
    "text": "hello, world!"
  }
}' "https://graph.facebook.com/v14.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
1 like
jorgensolli's avatar

@mstdmstd You would get the user reference from something like the New Conversation Webhook by the looks of it.

I haven't implemented this myself, so I cant be of much further help. I'm just referencing the documentation at this point.

But yeah according to the webhook that will return the user ref https://developers.facebook.com/docs/messenger-platform/discovery/facebook-chat-plugin/#new-conversations

{
  "sender":{
    "user_ref":"<USER_REF>"
  },
  "recipient":{
    "id":"<PAGE_ID>"
  },
  "timestamp":1458692752478,
  "postback":{
    "title": "<TITLE_FOR_THE_CTA>",  
    "payload": "<USER_DEFINED_PAYLOAD>",
    "referral": {
      "ref": "<USER_DEFINED_REFERRAL_PARAM>",
      "source": "CUSTOMER_CHAT_PLUGIN",
      "type": "OPEN_THREAD",
    }
  }
}

Please or to participate in this conversation.