Create a Messenger app and page.
If you don't have a Heroku account, create one. Ensure you have the Heroku CLI installed.
Fork this repository, then clone it:
git clone https://github.com/.../iart-bot.git
cd iart-bot
Get the App ID:
Paste it in public/index.html
, in addition to the ID of your page.
Set the values in config/default.json
:
Get the App Secret from the App Dashboard:
Select your page and get the Page Access Token:
Finally choose any string for the validationToken
.
Run the following commands to create a Heroku app and deploy the code.
heroku create
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add https://github.com/ricardocerq/heroku-prolog-buildpack.git
git add .
git commit -m "set values"
git push heroku master
heroku open
A browser window will open with the URL of your Heroku app. Copy it.
In the Webhooks section, click "Setup Webhooks".
In the "Callback URL" paste the URL and add /webhook
at the end. Under "Verify Token" set the string you choose for the validationToken
. Under "Subscription Fields", select messages
and messaging_postbacks
.
Then select your page.
And click "Subscribe".
Go back to your Heroku app and click the "Message us" button and chat away!
Refer to the Messenger bot tutorial and the Heroku NodeJS tutorial if you get stuck.
Replace the predicate answer/3
in prolog/request.pl
to implement the functionality of your bot. To redeploy, push to heroku/master
.
To add support for more Web API's, add a fact ws/1
with the atom representing it. Add a fact ws_info/2
with the information necessary to make an API call (keys, ids, host, path, etc):
ws_info(atom, [
key=<KEY>,
host=<HOST>,
path=<PATH>,
]).
Then use get_ws_info to get the data in ws_info by passing an association list Key=Value where Key is the parameter to extract and Value is a variable that will contain the value associated with the atom in the ws_info predicate. Then call request/6 with the hostname, the base path to the API, the path parameters to the API (will be separated by "/" in the URL), then the search parameters and finally the headers to add to the request specific to that web service. The result will be a Prolog term representing the JSON object returned by the API.