A Facebook Messenger Bot Example in Clojure
-
Setup a Facebook Page, Facebook app, create a Page Access Token and link the app to the page by following this step-by-step guide.
-
Download the repository: lemmings-io/02-facebook-example
-
Extract it into the
/lemmings/clojure/projects
directory. -
Start a new VM shell session via
vagrant ssh
-
In the VM shell change into the facebook-example project directory
cd 02-facebook-example/
-
Run
ngrok http 3000
(read more about ngrok) -
Start another new VM shell session via
vagrant ssh
-
Add your Facebook Page Access Token to your environment
export FB_PAGE_ACCESS_TOKEN="<YOUR_FB_PAGE_ACCESS_TOKEN>"
-
Start the local server
lein ring server-headless
Via the lein-ring doc: by default, this command attempts to find a free port, starting at 3000.
-
Visit the https URL as shown in step 4.
E.g.https://0db8caac.ngrok.io
If everything went right, you'll see "Hello Lemming :)" in your Browser 🎈
-
In your Facebook Developer App go to "Webhooks" in the left sidebar and add
Callback URL
andVerify Token
accordingly: -
Click "Verify and Save" and your app is connected to Facebook's Messenger API 🎈
-
Go to your Facebook Page and send a message and your bot echo's your input. Congratulations!💧
Check out the code to find out more 🙂
Note: This clojure app is ready for deployment on Heroku and based on Heroku's Clojure Getting Started Example.