Original Coast Clothing is a fictional clothing brand created to showcase the key features of the Instagram Platform delivering a great customer experience. Using this demo as inspiration, anyone can create a delightful Messenger API support for Instagram experience that leverages both automation and live customer support. Open-source code for the app and a guide on how to deploy the experience on your local environment or remote server are provided.
A Developer Account that can perform Tasks on your Page. A Developer Account allows you to create new apps, which are the core of any Facebook integration. You can register as a developer by going to the Facebook Developers website and clicking the “Get Started” button.
The objective of this section is to gather all the access tokens and ids necessary for the Instagram app to successfully send and receive messages. Before you begin, make sure you have completed all of the requirements listed above. At this point you should have a Page, a registered Facebook app, and an Instagram Professional account.
If you just created a new Facebook app, it is probably in development mode. Note that apps in this mode are only allowed to message people connected to the app (Admins, Developers and Testers). You can continue with this guide in this mode, but once your app is ready to be public, the app needs to go through app review for the instagram_manage_messages permission. For more info, see App Review
Configure your Instagram integration by following the Getting Started documentation.
Add some Instagram test accounts that you’ll use to test the experience.
The experience can be automatically deployed to Heroku or Glitch using the following buttons. You will be prompted to enter the needed environment variables to complete the setup.
A tunneling service exposes your local webserver to an external URL that can be reached by Facebook webhooks. There are many such services. In this example, we will use ngrok.
1. Clone the repo
Clone the repository to your local machine:
git clone https://github.com/fbsamples/original-coast-clothing-ig.git
cd original-coast-clothing-ig
2. Install tunneling service
If not already installed, install ngrok via download or via command line:
$ npm install -g ngrok
In the directory of this repo, request a tunnel to your local server with your preferred port
$ ngrok http 3000
The screen should show the ngrok status:
Session Status online
Account Redacted (Plan:iuluufkccebegkhifrlgfhudrtbthgln Free)
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://1c3b838deacb.ngrok.io -> http://localhost:3000
Forwarding https://1c3b838deacb.ngrok.io -> http://localhost:3000
Note the https URL of the external server that is fowarded to your local machine. In the above example, it is https://1c3b838deacb.ngrok.io.
3. Install the dependencies
Open a new terminal tab, also in the repo directiory.
Note the name given to your app. In this example, it was mystic-wind-83.
5. Set your environment variables
On the Heroku App Dashboard, find your app and set up the config vars following the comments in the file .sample.env
Alternatively, you can set env variables from the command line like this:
$ heroku config:set PAGE_ID=XXXX
6. Deploy the code
$ git push heroku master
7. View log output
$ heroku logs --tail
Connect your webhook
Now that your server is running, your webhook endpoint is at the path /webhook. In the Heroku example above, this would be http://mystic-wind-83.herokuapp.com/webhook.
Set up your webhook by following the [Messenger Platform Webhooks guide](/documentation/business-messaging/messenger-platform/webhooks
After the webhook subscription is validated, subscribe to the following events:
comments
messages
messaging_postbacks
Test the webhooks by clicking the “Test” buttons next to the subscribed events. You should see the test events in the log output of your server.
Test that your app setup is successful
While logged in to an account with the role of “Instagram Tester”, try sending a message to the Instagram account connected to your Page, or leaving a comment on a post.
If you see a response to your message in Instagram, you have fully set up your app! Voilà!
Troubleshooting
The app only replies to me, but not someone else
The Facebook app is likely still in Development Mode. You can add someone as a tester of the app, if they accept, the app will be able to message them. Once ready, you may request the instagram_manage_messages permission to be able to reply to anyone.