Send a Facebook message
You can then use the Messages API to respond to the inbound message received from the Facebook User.
Replace the following variables in the example below with actual values:
| Key | Description |
|---|---|
FB_SENDER_ID | Your Page ID. The FB_SENDER_ID is the same as the to.id value you received in the inbound messenger event on your Inbound Message Webhook URL. |
FB_RECIPIENT_ID | The PSID of the user you want to reply to. The FB_RECIPIENT_ID is the PSID of the Facebook User you are messaging. This value is the from.id value you received in the inbound messenger event on your Inbound Message Webhook URL. |
Example
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named send-text.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a file named SendMessengerText and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.messenger with the package containing SendMessengerText:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a file named SendMessengerText and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.messenger with the package containing SendMessengerText:
Prerequisites
Prerequisites
Create a file named send-text.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named send-text.rb and add the following code:
Run your code
Save this file to your machine and run it:
TIP: If testing using Curl you will need a JWT. You can see how to create one in the documentation on creating a JWT.
Sending a Facebook Messenger message
The Messages API provides the ability to send messages to various channels, including Facebook Messenger, SMS, WhatsApp and Viber. This task looks at using the Messages API to send a Facebook Messenger message.