Setting Up Facebook
To use Facebook Channel, you have to create a Facebook app in the developer portal. You can find more details about creating Facebook apps here.
Prerequisites
- A valid facebook account.
- A valid facebook page.
Register A Facebook App
- Go to Facebook developer portal and click on the "Create App" button
- Select the option "Other".
- For the app type, choose "Business".
- Enter basic details like the app name and email.
Once you register your Facebook App, you will have to obtain the App Id
and App Secret
. These values will be available in the app settings and will be required while setting up Chatwoot environment variables.
Configuring the Environment Variables in Chatwoot
Configure the following Chatwoot environment variables with the values you obtained during the Facebook app setup. The FB_VERIFY_TOKEN
should be a unique and secure string that you provide when configuring the Facebook app. Generate a random string and set it as the FB_VERIFY_TOKEN
. Facebook will include this string in all verification requests.
Restart the Chatwoot server after updating the environment variables
FB_VERIFY_TOKEN=
FB_APP_SECRET=
FB_APP_ID=
Configure Facebook Login
- Add the Facebook Login product via the Facebook app dashboard.
- Enable
Web OAuth Login
,Login with Javascript SDK
and add your self-hosted domain to theAllowed Domains for the JavaScript SDK
input.
Configure the Facebook App
- In the app settings, add your
Chatwoot installation domain
as your app domain.
- In the products section in your app settings page, Add "Messenger"
- Go to the Messenger settings and configure the call back URL
- Provide the Callback URL as
{your_chatwoot_installation_url}/bot
and the Verify token asFB_VERIFY_TOKEN
from your environment variable.
- Head over to Chatwoot and create a Messenger inbox. Choose a page for which your Facebook developer account has admin access to. Please refer to this guide for more details on creating a Messenger inbox in Chatwoot.
Testing the Facebook channel
Until the application is approved for production, Facebook wouldn't send the new messages on your page to Chatwoot.
To test the changes until the app is approved for production. Follow the steps
- Head over to the messenger section in your app settings page, in Facebook developers.
- Click
Add or remove pages
and connect the page which you choose while creating the Chatwoot Messenger inbox.
- After connecting the pages, Click on
Add subscriptions
from the connected page.
- Subscribe to the following fields and save the subscription.
messages
messaging_postbacks
message_deliveries
message_reads
message_echoes
- Send a message to the connected page from your Facebook account and it should appear in Chatwoot now.
Going into production.
Before you can start using your Facebook app in production, you will have to get it verified by Facebook. Refer to the docs on getting your app verified.
Obtain advanced access to the required permissions mentioned below for your Facebook app
pages_messaging
pages_show_list
pages_manage_metadata
business_management
pages_read_engagement
Make sure your facebook app subscription version is 17.0, we have updated the FB subscription with the latest version, so change the permission subscription version under the facebook app webhooks option.
Developing or Testing Facebook Integration in your machine
Install ngrok on your machine. This will be required since Facebook Messenger API's will only communicate via https.
brew cask install ngrok
Configure ngrok to route to your Rails server port.
ngrok http 3000
Go to the Facebook developers page and navigate into your app settings. In the app settings, add localhost
as your app domain.
In the Messenger settings page, configure the callback url with the following value.
{your_ngrok_url}/bot
Update verify token in your Chatwoot environment variables.
You will also have to add a Facebook page to your Access Tokens
section in your Messenger settings page.
Restart the Chatwoot local server. Your Chatwoot setup will be ready to receive Facebook messages.
Facebook API version
We support facebook API version v13.0 going forward, which you can update in the facebook app advanced settings.
Test your local Setup
- After finishing the set-up above, create a Facebook inbox after logging in to your Chatwoot Installation.
- Send a message to your page from Facebook.
- Wait and confirm incoming requests to
/bot
endpoint in your ngrok screen.