The request shown here is used to start tasks from external systems.
Its operation proceeds as follows. The portal receives the webhook after which it passes it to the job which the runner retrieves, as the webhook was passed from the very beginning therefore the executed script has access to the data passed by the webhook.
Creating webhook
To create a webhook you must edit the workflow in which you want to add it. Once there, you need to find the triggers section and then select Add trigger -> Webhook there.
Then you enter the name of the webhook you are creating and any parameters if you need them. Once you have done that click save, and the webhook has been created!
Running webhook
After creating the webhook, you may notice that a link has been generated that you will use to run the job from an external source.
To run the webhook send a request to this address, if you want you can also add various parameters that will appear in the body of the job but it is not required. Below is shown an example in which one parameter was sent.
genre - success or failure is sent at the end of the process, update while the script is running.
code - here Linux-standard - the error code returned by the script, 0 when success, anything over when not.
result - what the script threw out.
attachments - according to the documentation here Attachments.
Currently, we can change the work status to 3 different types, and these are:
Update
Such information comes out from the bot during Job execution, can come down many times and we display it in the user panel.
# Request
POST /api/v1/jobs/94916326-9344-43f5-9187-1aea2931eac7/results
# Response
{
"genre": "update",
"result": {
"lorem": "ipsum",
"hello": "world"
}, // result object, any json
"attachments": [
(...) // check the Attachment docs
]
}
Success
# Request
POST /api/v1/jobs/94916326-9344-43f5-9187-1aea2931eac7/results
# Response
{
"genre": "success",
"code": 0, // code (shell) returned by the process
"result": {
"lorem": "ipsum",
"hello": "world"
}, // result object, any json
"attachments": [
(...) // check the Attachment docs
]
}
Failure
# Request
POST /api/v1/jobs/94916326-9344-43f5-9187-1aea2931eac7/results
# Response
{
"genre": "failure",
"code": 127, // code (shell) returned by the process
"result": {
"lorem": "ipsum",
"hello": "world"
}, // result object, any json
"attachments": [
(...) // check the Attachment docs
]
}
Assist Request
In some advanced cases, human intervention may be needed, and for these cases, we have this request that allows you to ask several types of questions.
The basic request should look like this, the different types will be described below.
# Request
POST /api/v1/jobs/123e4567-e89b-12d3-a456-426614174000/assist_requests
{
"expires_at": "YYYY-MM-DD HH:MM:SS", // until when the request will be valid
"question": "Is it assisted already?", // question content
"attachments": [],
"genre": "input", // type of assist request
(...) // here are the other parameters of the assist that differs by type
}
# Response
// Created
{
"status": "201 Created",
"id": "63be582f-d330-44ec-943b-8179e1b28c9a",
"url": "https://serwer.xxx.yyy.com/api/v1/assist_requests/d7dd76a0-b7a5-44d7-b98f-8712aa0e5505"
}
// Not responded yet
{
"status": "200 OK",
"time_left": 213213214 // in seconds or null when undefined - the amount of time left for the operator to respond
}
// Time Expired
{
"status": "410 Gone",
"time_left": 0
}
// Responded
{
"id": "xxxxxx-xxxxxx-xxxxx-xxxx", // response id
"responded_at": "YYYY-MM-DD HH:MM:SS", // when responded
// data of the user who made the reply
"user": {
"id": 123,
"email": "jan.kowalski@unitedideas.pl",
"full_name": "Jan Kowalski"
},
// response data that differs by type
(...)
}
Text input
{
(...) // standard request part
"genre": "input", // request type
"required": true, // is it required
"confirm": true, // is it necessary to confirm the selection in the interface?
"short": true, // when true then input, when false then textarea
"name": "login", // field name, reference for future
"default": "blablabla" // pre-populate interface with this answer, non-mandatory
"validate": "/\A[^.]+\.[^.]+\Z/" # valid javascript regex to validate answer
"error": "Login may contain only letters and saves" # validation alert if not matches
}
# Response
{
(...) // standard response part
"response": "loremipsum324"
}
Yes/No
{
(...) // standard request part
"genre": "yes_or_not", // request type
"required": true, // is it required
"confirm": true, // is it necessary to confirm the selection in the interface?
"default": true // not mandatory
"positive": "Yup", // positive value
"negative": "Nope", // negative value
}
# Response
{
(...) // standard response part
"response": true // or false
}
To get to the parameters sent in the webhook you need to get yourself the data of the whole job, which you can get to by the environment variable (ANYROBOT_PAYLOAD_FILE) that points the path to the payload file. Feel free to check the documentation related to to learn more about this topic.
File, of any type. The body field is encoded according to , and has a format like this: