A webhook is a callback mechanism that allows you to instantly respond to the appearance of a task at a certain step.
To get started, you must do the following:
When a task is delivered to a bot’s Inbox, Pyrus sends the HTTPS POST request to the event handler. Your bot must respond to the request with the 2XX status within 60 seconds of this call. If you need to add a comment to the task, you can write it into the response body. The response body has the same structure as the POST /tasks/{task-id}/comments.
Example request:
{ event: "comment", access_token: "Dfpb1we4...", task_id: 1532, user_id: 1725, "task": { "text": "Budget approval", "id": 11611, "create_date": "2017-08-17T15:32:11Z", "last_modified_date": "2017-08-17T15:32:11Z", "author": { "id": 1731, "first_name": "Bob", "last_name": "Smith", "email": "Bob.Smith@gmail.com" }, "responsible": { "id": 1245, "first_name": "my bot", "last_name": "", "email": bot@4e83a7da-3ba1-4a16-a1d8-21bbd1ad9592 }, "participants": [ { "id": 1245, "first_name": "my bot", "last_name": "", "email": bot@4e83a7da-3ba1-4a16-a1d8-21bbd1ad9592 }, { "id": 1731, "first_name": "Bob", "last_name": "Smith", "email": "Bob.Smith@gmail.com" } ], "comments": [ { "id": 13767, "create_date": "2017-08-17T15:32:11Z", "text": "Budget approval", "author": { "id": 1731, "first_name": "Bob", "last_name": "Smith", "email": "Bob.Smith@gmail.com" }, "reassigned_to": { "id": 1245, "first_name": "my bot", "last_name": "", "email": bot@4e83a7da-3ba1-4a16-a1d8-21bbd1ad9592 }, "participants_added": [ { "id": 1245, "first_name": "my bot", "last_name": "", "email": bot@4e83a7da-3ba1-4a16-a1d8-21bbd1ad9592 }, { "id": 1731, "first_name": "Bob", "last_name": "Smith", "email": "Bob.Smith@gmail.com" } ] } ] } }
If the bot server is unavailable or responds with a status other than 2xx, Pyrus sends a second request in 61 seconds and a third one in 122 seconds. You can see the number of attempts in X-Pyrus-Retry, the additional header of the request. If Pyrus fails to communicate within three attempts, it will stop trying to call the bot until someone comments on the task.
Request headers:
git clone https://github.com/simplygoodsoftware/heroku-python-bot.git cd heroku-python-bot
{ "SECRET_KEY": "Bot-Secret-Key" }
heroku create git add . git commit -m "replaced SECRET_KEY in config.json" git push heroku master heroku ps:scale web=1
Hello, {user_name}! You said "{comment_text}".