This is an implementation of a Facebook Messenger bot written in Google Apps Script (a javascript runtime in the google cloud). The advantage of using Google Apps Script is it allows GET and POST requests to be made and recieved for free and without having to run your own server. It also allows arbitrary temporal triggers to be set so functions get be run at exact times or on minutely/hourly/daily/weekly intervals.
- Go to http://script.google.com and copy the code in. Save and name the script and go to the cloud icon (5th icon from the left), change the bottom dropdown (“Who has access to the app”) to “Anyone, even anonymous”, and click “Publish”. Copy that URL for use in facebook
- Follow Facebook’s Getting Started tutorial and, when it asks for the callback function for the webhook, paste the previous url in
- After making any changes, the app needs to be update
- Go to the cloud icon again, click the “Versions” dropdown and go the bottom for “New”, then click the “Update” button
The main place to make changes is around line 117 with the case statements, enter the keywords you want and change/write the functions you want that keyword to call (the left panel of this page has many good example templates, just copy what’s between the “message” key into the new function (More complicated use cases with callbacks and buttons is possible)