Flows

Definitions

Flow definitions are defined as a list of nodes, the first node being the entry into the flow. A flow can have zero nodes and therefore be a no-op up to a maximum of 1,000 nodes.

The simplest possible flow containing no nodes whatsoever contains the following fields:

For example:

{
    "uuid": "b7bb5e7c-ad49-4e65-9e24-bf7f1e4ff00a",
    "name": "Empty Flow",
    "language": "eng",
    "type": "messaging",
    "nodes": []
}

Nodes

A node consists of:

At its simplest, a node can be just a single action with no exits, wait or router, such as:

{
    "uuid":"5a06445e-d790-4bd3-a10b-b47bdcc9abed",
    "actions":[{
        "uuid": "abc0a2bf-6b4a-4ee0-83e1-1eebae6948ac",
        "type": "send_msg",
        "text": "What is your name?"
    }]
}

If a node wishes to route to another node, it can do so by defining one or more exits, each with the UUID of the node that is next. Without a router defined, the first exit will always be taken.

An exit consists of:

{
    "uuid":"5a06445e-d790-4bd3-a10b-b47bdcc9abed",
    "actions":[{
        "uuid": "abc0a2bf-6b4a-4ee0-83e1-1eebae6948ac",
        "type": "send_msg",
        "text": "What is your name?"
    }],
    "exits": [{
        "uuid":"eb7defc9-3c66-4dfc-80bc-825567ccd9de",
        "destination_uuid":"ee0bee3f-34b3-4275-af78-f9ff52c82e6a"
    }]
}

Actions

Actions on a node generate events which can then be ingested by the engine container. In some cases the actions cause an immediate action, such as calling a webhook, in others the engine container is responsible for taking the action based on the event that is output, such as sending messages or updating contact fields. In either case the internal state of the engine is always updated to represent the new state so that flow execution is consistent. For example, while the engine itself does not have access to a contact store, it updates its internal representation of a contact’s state based on action performed on a flow so that later references in the flow are correct.

add_contact_groups

Can be used to add a contact to one or more groups. A contact_groups_changed event will be created for the groups which the contact has been added to.

Action

{
    "type": "add_contact_groups",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "groups": [
        {
            "uuid": "1e1ce1e1-9288-4504-869e-022d1003c72a",
            "name": "Customers"
        }
    ]
}

Event

{
    "uuid": "019fd351-4dd1-7183-a98c-c3ed5728bb2f",
    "type": "contact_groups_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "groups_added": [
        {
            "uuid": "1e1ce1e1-9288-4504-869e-022d1003c72a",
            "name": "Customers"
        }
    ]
}

add_contact_urn

Can be used to add a URN to the current contact. A contact_urns_changed event will be created if the URN was added. The action sets a _has_urn local to the URN if the contact has it after the action (whether newly added or pre-existing), and to an empty string otherwise.

Action

{
    "type": "add_contact_urn",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "scheme": "tel",
    "path": "@results.phone_number.value"
}

Event

{
    "uuid": "019fd351-4dd1-7c04-957d-3a8e004e73a9",
    "type": "contact_urns_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "urns": [
        "tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d",
        "twitterid:54784326227#nyaruka",
        "mailto:foo@bar.com",
        "tel:+12344563452"
    ]
}

add_input_labels

Can be used to add labels to the last user input on a flow. An input_labels_added event will be created with the labels added when this action is encountered. If there is no user input at that point an error will be logged and this action will be ignored.

Action

{
    "type": "add_input_labels",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "labels": [
        {
            "uuid": "3f65d88a-95dc-4140-9451-943e94e06fea",
            "name": "Spam"
        }
    ]
}

Event

{
    "uuid": "019fd351-4dd2-7403-84ae-2dc9f2d6a060",
    "type": "input_labels_added",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "input_uuid": "0197b335-6ded-79a4-95a6-3af85b57f108",
    "labels": [
        {
            "uuid": "3f65d88a-95dc-4140-9451-943e94e06fea",
            "name": "Spam"
        }
    ]
}

call_llm

Can be used to call an LLM. The instructions and input fields may be templates and will be evaluated at runtime.

An llm_called event will be created if the LLM could be called. The action sets the local specified by output_local to the output of the LLM, or to <ERROR> if the call failed.

Action

{
    "type": "call_llm",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "llm": {
        "uuid": "14115c03-b4c5-49e2-b9ac-390c43e9d7ce",
        "name": "GPT-4"
    },
    "instructions": "Categorize the following text as positive or negative",
    "input": "@input.text",
    "output_local": "_llm_output"
}

Event

{
    "uuid": "019fd351-4dd2-7b8b-a8a2-3807c9c3eb6a",
    "type": "llm_called",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "llm": {
        "uuid": "14115c03-b4c5-49e2-b9ac-390c43e9d7ce",
        "name": "GPT-4"
    },
    "instructions": "Categorize the following text as positive or negative",
    "input": "Hi there",
    "output": "negative",
    "tokens": {
        "input": 45,
        "output": 78
    },
    "elapsed_ms": 0
}

call_resthook

Can be used to call a resthook. A resthook_called event will be created with the payload sent to subscribers, and a webhook_called event will be created for each subscriber called. If the resthook isn’t found, this action does nothing.

This action always updates the @webhook context value: one of the subscriber calls (prioritizing failures) is picked as the result of the action, and if there were no subscriber calls, it will be cleared.

If this action has result_name set, a result will be created from the picked call in the same way as for call_webhook.

Action

{
    "type": "call_resthook",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "resthook": "new-registration"
}

Event

[
    {
        "uuid": "019fd351-4dd3-7e22-94b1-31442acf0ff7",
        "type": "resthook_called",
        "created_on": "2018-04-11T18:24:30.123456Z",
        "resthook": "new-registration",
        "payload": {
            "channel": {
                "address": "+17036975131",
                "name": "My Android Phone",
                "uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d"
            },
            "contact": {
                "language": "eng",
                "name": "Ryan Lewis",
                "urn": "tel:+12024561111",
                "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f"
            },
            "flow": {
                "name": "Registration",
                "revision": 123,
                "uuid": "50c3706e-fedb-42c0-8eab-dda3335714b7"
            },
            "input": {
                "attachments": [
                    {
                        "content_type": "image/jpeg",
                        "url": "http://s3.amazon.com/bucket/test.jpg"
                    },
                    {
                        "content_type": "audio/mp3",
                        "url": "http://s3.amazon.com/bucket/test.mp3"
                    }
                ],
                "channel": {
                    "address": "+17036975131",
                    "name": "My Android Phone",
                    "uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d"
                },
                "created_on": "2017-12-31T11:35:09.123456Z",
                "text": "Hi there",
                "type": "msg",
                "urn": {
                    "display": "(206) 555-1212",
                    "path": "+12065551212",
                    "scheme": "tel"
                },
                "uuid": "0197b335-6ded-79a4-95a6-3af85b57f108"
            },
            "path": [
                {
                    "arrived_on": "2018-04-11T18:24:30.123456Z",
                    "exit_uuid": "d7a36118-0a38-4b35-a7e4-ae89042f0d3c",
                    "node_uuid": "72a1f5df-49f9-45df-94c9-d86f7ea064e5",
                    "uuid": "59ad8481-1332-4457-b20c-e3cb6203e029"
                },
                {
                    "arrived_on": "2018-04-11T18:24:30.123456Z",
                    "exit_uuid": "100f2d68-2481-4137-a0a3-177620ba3c5f",
                    "node_uuid": "3dcccbb4-d29c-41dd-a01f-16d814c9ab82",
                    "uuid": "57006809-aa29-4493-89aa-1577771fa183"
                },
                {
                    "arrived_on": "2018-04-11T18:24:30.123456Z",
                    "exit_uuid": "d898f9a4-f0fc-4ac4-a639-c98c602bb511",
                    "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                    "uuid": "5991bf15-08ea-4d25-b384-a4094c3d60be"
                },
                {
                    "arrived_on": "2018-04-11T18:24:30.123456Z",
                    "exit_uuid": "9fc5f8b4-2247-43db-b899-ab1ac50ba06c",
                    "node_uuid": "c0781400-737f-4940-9a6c-1ec1c3df0325",
                    "uuid": "5f9e5e2d-ea8c-40fd-b4dd-bb13b355a627"
                }
            ],
            "results": {
                "2factor": {
                    "category": "",
                    "category_localized": "",
                    "created_on": "2018-04-11T18:24:30.123456Z",
                    "input": "",
                    "name": "2Factor",
                    "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                    "value": "34634624463525"
                },
                "favorite_color": {
                    "category": "Red",
                    "category_localized": "Red",
                    "created_on": "2018-04-11T18:24:30.123456Z",
                    "input": "",
                    "name": "Favorite Color",
                    "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                    "value": "red"
                },
                "phone_number": {
                    "category": "",
                    "category_localized": "",
                    "created_on": "2018-04-11T18:24:30.123456Z",
                    "input": "",
                    "name": "Phone Number",
                    "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                    "value": "+12344563452"
                },
                "webhook": {
                    "category": "Success",
                    "category_localized": "Success",
                    "created_on": "2018-04-11T18:24:30.123456Z",
                    "input": "GET http://127.0.0.1:49998/?content=%7B%22results%22%3A%5B%7B%22state%22%3A%22WA%22%7D%2C%7B%22state%22%3A%22IN%22%7D%5D%7D",
                    "name": "webhook",
                    "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                    "value": "200"
                }
            },
            "run": {
                "created_on": "2018-04-11T18:24:30.123456Z",
                "uuid": "019fd351-4db9-753a-95cf-9fca95f1c30a"
            }
        }
    },
    {
        "uuid": "019fd351-4dd4-74b4-809a-c6ff6fcaed38",
        "type": "webhook_called",
        "created_on": "2018-04-11T18:24:30.123456Z",
        "url": "http://127.0.0.1:49998/?cmd=success",
        "status_code": 200,
        "request": "POST /?cmd=success HTTP/1.1\r\nHost: 127.0.0.1:49998\r\nUser-Agent: goflow-testing\r\nContent-Length: 2619\r\nContent-Type: application/json\r\nAccept-Encoding: gzip\r\n\r\n{\"channel\":{\"address\":\"+17036975131\",\"name\":\"My Android Phone\",\"uuid\":\"57f1078f-88aa-46f4-a59a-948a5739c03d\"},\"contact\":{\"language\":\"eng\",\"name\":\"Ryan Lewis\",\"urn\":\"tel:+12024561111\",\"uuid\":\"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f\"},\"flow\":{\"name\":\"Registration\",\"revision\":123,\"uuid\":\"50c3706e-fedb-42c0-8eab-dda3335714b7\"},\"input\":{\"attachments\":[{\"content_type\":\"image/jpeg\",\"url\":\"http://s3.amazon.com/bucket/test.jpg\"},{\"content_type\":\"audio/mp3\",\"url\":\"http://s3.amazon.com/bucket/test.mp3\"}],\"channel\":{\"address\":\"+17036975131\",\"name\":\"My Android Phone\",\"uuid\":\"57f1078f-88aa-46f4-a59a-948a5739c03d\"},\"created_on\":\"2017-12-31T11:35:09.123456Z\",\"text\":\"Hi there\",\"type\":\"msg\",\"urn\":{\"display\":\"(206) 555-1212\",\"path\":\"+12065551212\",\"scheme\":\"tel\"},\"uuid\":\"0197b335-6ded-79a4-95a6-3af85b57f108\"},\"path\":[{\"arrived_on\":\"2018-04-11T18:24:30.123456Z\",\"exit_uuid\":\"d7a36118-0a38-4b35-a7e4-ae89042f0d3c\",\"node_uuid\":\"72a1f5df-49f9-45df-94c9-d86f7ea064e5\",\"uuid\":\"59ad8481-1332-4457-b20c-e3cb6203e029\"},{\"arrived_on\":\"2018-04-11T18:24:30.123456Z\",\"exit_uuid\":\"100f2d68-2481-4137-a0a3-177620ba3c5f\",\"node_uuid\":\"3dcccbb4-d29c-41dd-a01f-16d814c9ab82\",\"uuid\":\"57006809-aa29-4493-89aa-1577771fa183\"},{\"arrived_on\":\"2018-04-11T18:24:30.123456Z\",\"exit_uuid\":\"d898f9a4-f0fc-4ac4-a639-c98c602bb511\",\"node_uuid\":\"f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03\",\"uuid\":\"5991bf15-08ea-4d25-b384-a4094c3d60be\"},{\"arrived_on\":\"2018-04-11T18:24:30.123456Z\",\"exit_uuid\":\"9fc5f8b4-2247-43db-b899-ab1ac50ba06c\",\"node_uuid\":\"c0781400-737f-4940-9a6c-1ec1c3df0325\",\"uuid\":\"5f9e5e2d-ea8c-40fd-b4dd-bb13b355a627\"}],\"results\":{\"2factor\":{\"category\":\"\",\"category_localized\":\"\",\"created_on\":\"2018-04-11T18:24:30.123456Z\",\"input\":\"\",\"name\":\"2Factor\",\"node_uuid\":\"f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03\",\"value\":\"34634624463525\"},\"favorite_color\":{\"category\":\"Red\",\"category_localized\":\"Red\",\"created_on\":\"2018-04-11T18:24:30.123456Z\",\"input\":\"\",\"name\":\"Favorite Color\",\"node_uuid\":\"f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03\",\"value\":\"red\"},\"phone_number\":{\"category\":\"\",\"category_localized\":\"\",\"created_on\":\"2018-04-11T18:24:30.123456Z\",\"input\":\"\",\"name\":\"Phone Number\",\"node_uuid\":\"f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03\",\"value\":\"+12344563452\"},\"webhook\":{\"category\":\"Success\",\"category_localized\":\"Success\",\"created_on\":\"2018-04-11T18:24:30.123456Z\",\"input\":\"GET http://127.0.0.1:49998/?content=%7B%22results%22%3A%5B%7B%22state%22%3A%22WA%22%7D%2C%7B%22state%22%3A%22IN%22%7D%5D%7D\",\"name\":\"webhook\",\"node_uuid\":\"f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03\",\"value\":\"200\"}},\"run\":{\"created_on\":\"2018-04-11T18:24:30.123456Z\",\"uuid\":\"019fd351-4db9-753a-95cf-9fca95f1c30a\"}}",
        "response": "HTTP/1.1 200 OK\r\nContent-Length: 16\r\nContent-Type: text/plain; charset=utf-8\r\nDate: Wed, 11 Apr 2018 18:24:30 GMT\r\n\r\n{ \"ok\": \"true\" }",
        "elapsed_ms": 0,
        "retries": 0,
        "sizes": {
            "request": 2778,
            "response": 133
        },
        "status": "success",
        "resthook": "new-registration"
    }
]

call_webhook

Can be used to call an external service. The body, header and url fields may be templates and will be evaluated at runtime. A webhook_called event will be created based on the results of the HTTP call.

This action always updates the @webhook context value: if a call was made it will be the result of that call, and if not (e.g. the URL evaluated to something invalid) it will be cleared.

If this action has result_name set, a result will be created with that name. The value of the result will be the response status code and the category will be Success or Failure. If the response body is valid JSON which is less than 10000 bytes, it will be accessible as extra on the result.

Action

{
    "type": "call_webhook",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "method": "GET",
    "url": "http://localhost:49998/?cmd=success",
    "headers": {
        "Authorization": "Token AAFFZZHH"
    },
    "result_name": "webhook"
}

Event

{
    "uuid": "019fd351-4dd5-7da9-a966-b98cee34c80a",
    "type": "webhook_called",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "url": "http://localhost:49998/?cmd=success",
    "status_code": 200,
    "request": "GET /?cmd=success HTTP/1.1\r\nHost: localhost:49998\r\nUser-Agent: goflow-testing\r\nAuthorization: Token AAFFZZHH\r\nAccept-Encoding: gzip\r\n\r\n",
    "response": "HTTP/1.1 200 OK\r\nContent-Length: 16\r\nContent-Type: text/plain; charset=utf-8\r\nDate: Wed, 11 Apr 2018 18:24:30 GMT\r\n\r\n{ \"ok\": \"true\" }",
    "elapsed_ms": 0,
    "retries": 0,
    "sizes": {
        "request": 135,
        "response": 133
    },
    "status": "success"
}

enter_flow

Can be used to start a contact down another flow. The current flow will pause until the subflow exits or expires.

A run_started event will be created to record that a new run was started. If the flow doesn’t exist or its type can’t be entered from the current session, the run will end in failure.

Action

{
    "type": "enter_flow",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "flow": {
        "uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
        "name": "Collect Language"
    }
}

Event

[]

open_ticket

Can be used to open a ticket for the contact if they don’t already have an open ticket.

If a ticket is opened, a ticket_opened event will be created - and a ticket_note_added event if the action has a non-empty note. The action sets a _new_ticket local to the UUID of the new ticket, or to an empty string if no ticket was opened.

Action

{
    "type": "open_ticket",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "topic": {
        "uuid": "472a7a73-96cb-4736-b567-056d987cc5b4",
        "name": "Weather"
    },
    "assignee": {
        "uuid": "0c78ef47-7d56-44d8-8f57-96e0f30e8f44",
        "name": "Bob McTickets"
    },
    "note": "@input"
}

Event

[]

play_audio

Can be used to play an audio recording in a voice flow. It will generate an ivr_created event if there is a valid audio URL. This will contain a message which the caller should handle as an IVR play command using the audio attachment.

Action

{
    "type": "play_audio",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "audio_url": "http://uploads.temba.io/2353262.m4a"
}

Event

{
    "uuid": "019fd351-4dd7-70a3-8923-5011ee188a4d",
    "type": "ivr_created",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "msg": {
        "urn": "tel:+12065551212",
        "channel": {
            "uuid": "fd47a886-451b-46fb-bcb6-242a4046c0c0",
            "name": "Nexmo"
        },
        "text": "",
        "attachments": [
            "audio:http://uploads.temba.io/2353262.m4a"
        ],
        "locale": "eng-US"
    }
}

remove_contact_groups

Can be used to remove a contact from one or more groups. A contact_groups_changed event will be created for the groups which the contact is removed from. Groups can either be explicitly provided or all_groups can be set to true to remove the contact from all non-query based groups.

Action

{
    "type": "remove_contact_groups",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "groups": [
        {
            "uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
            "name": "Registered Users"
        }
    ]
}

Event

{
    "uuid": "019fd351-4dd7-77a7-a207-1680d9c0b689",
    "type": "contact_groups_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "groups_removed": [
        {
            "uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
            "name": "Testers"
        }
    ]
}

request_optin

Was used to request an optin from the contact but is no longer supported.

An error event will be created.

Action

{
    "type": "request_optin",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "optin": {
        "uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb",
        "name": "Joke Of The Day"
    }
}

Event

{
    "uuid": "019fd351-4dd7-7e42-a1fe-775299733346",
    "type": "error",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "text": "opt-in requests are no longer supported",
    "code": "action:unsupported"
}

say_msg

Can be used to communicate with the contact in a voice flow by either reading a message with TTS or playing a pre-recorded audio file. It will generate an ivr_created event if there is a valid audio URL or backdown text. This will contain a message which the caller should handle as an IVR play command if it has an audio attachment, or otherwise an IVR say command using the message text.

Action

{
    "type": "say_msg",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "text": "Hi @contact.name, are you ready to complete today's survey?",
    "audio_url": "http://uploads.temba.io/2353262.m4a"
}

Event

{
    "uuid": "019fd351-4dd8-7298-99a3-375b9e29205d",
    "type": "ivr_created",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "msg": {
        "urn": "tel:+12065551212",
        "channel": {
            "uuid": "fd47a886-451b-46fb-bcb6-242a4046c0c0",
            "name": "Nexmo"
        },
        "text": "Hi Ryan Lewis, are you ready to complete today's survey?",
        "attachments": [
            "audio:http://uploads.temba.io/2353262.m4a"
        ],
        "locale": "eng-US"
    }
}

send_broadcast

Can be used to send a message to one or more contacts. It accepts a list of URNs, a list of groups and a list of contacts.

The URNs and text fields may be templates. A single broadcast_created event will be created with the evaluated text and the resolved recipients.

Action

{
    "type": "send_broadcast",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "urns": [
        "tel:+12065551212"
    ],
    "text": "Hi @contact.name, are you ready to complete today's survey?",
    "template": {
        "uuid": "3ce100b7-a734-4b4e-891b-350b1279ade2",
        "name": "revive_issue"
    },
    "template_variables": [
        "@contact.name"
    ]
}

Event

{
    "uuid": "019fd351-4dd8-7aec-8f4e-e2955c74585e",
    "type": "broadcast_created",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "translations": {
        "eng": {
            "text": "Hi Ryan Lewis, are you ready to complete today's survey?"
        }
    },
    "base_language": "eng",
    "urns": [
        "tel:+12065551212"
    ]
}

send_email

Can be used to send an email to one or more recipients. The subject, body and addresses can all contain expressions.

An email_sent event will be created if the email could be sent.

Action

{
    "type": "send_email",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "addresses": [
        "@urns.mailto"
    ],
    "subject": "Here is your activation token",
    "body": "Your activation token is @contact.fields.activation_token"
}

Event

{
    "uuid": "019fd351-4dda-7677-a4d8-bab6c01e389e",
    "type": "email_sent",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "to": [
        "foo@bar.com"
    ],
    "subject": "Here is your activation token",
    "body": "Your activation token is AACC55"
}

send_msg

Can be used to reply to the current contact in a flow. The text field may contain templates. The action will attempt to find pairs of URNs and channels which can be used for sending. If it can’t find such a pair, it will create a message without a channel or URN.

A msg_created event will be created with the evaluated text. If the action has a template set and a matching translation exists for the channel, the created message will use that template.

Action

{
    "type": "send_msg",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "text": "Hi @contact.name, are you ready to complete today's survey?",
    "template": {
        "uuid": "3ce100b7-a734-4b4e-891b-350b1279ade2",
        "name": "revive_issue"
    },
    "template_variables": [
        "@contact.name"
    ]
}

Event

{
    "uuid": "019fd351-4ddb-7087-bf5f-e2c414a53431",
    "type": "msg_created",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "msg": {
        "urn": "tel:+12024561111",
        "channel": {
            "uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d",
            "name": "My Android Phone"
        },
        "text": "Hi Ryan Lewis, are you ready to complete today's survey?",
        "locale": "eng-US"
    }
}

set_contact_channel

Can be used to change or clear the preferred channel of the current contact.

Because channel affinity is a property of a contact’s URNs, a contact_urns_changed event will be created if any changes are made to the contact’s URNs.

Action

{
    "type": "set_contact_channel",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "channel": {
        "uuid": "4bb288a0-7fca-4da1-abe8-59a593aff648",
        "name": "Facebook Channel"
    }
}

Event

[]

set_contact_field

Can be used to update a field value on the contact. The value is a template and white space is trimmed from the final value. An empty string clears the value. A contact_field_changed event will be created with the corresponding value.

Action

{
    "type": "set_contact_field",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "field": {
        "key": "gender",
        "name": "Gender"
    },
    "value": "Female"
}

Event

{
    "uuid": "019fd351-4ddc-7064-9d8a-f120e44f6e7e",
    "type": "contact_field_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "field": {
        "key": "gender",
        "name": "Gender"
    },
    "value": {
        "text": "Female"
    }
}

set_contact_language

Can be used to update the language of the contact. The language is a template and white space is trimmed from the final value. An empty string clears the language. A contact_language_changed event will be created with the corresponding value.

Action

{
    "type": "set_contact_language",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "language": "eng"
}

Event

[]

set_contact_name

Can be used to update the name of the contact. The name is a template and white space is trimmed from the final value. An empty string clears the name. A contact_name_changed event will be created with the corresponding value.

Action

{
    "type": "set_contact_name",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "name": "Bob Smith"
}

Event

{
    "uuid": "019fd351-4ddc-7c53-8bf2-1cda6c90eec9",
    "type": "contact_name_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "name": "Bob Smith"
}

set_contact_status

Can be used to update the status of the contact, e.g. to block or unblock the contact. A contact_status_changed event will be created with the corresponding value.

Action

{
    "type": "set_contact_status",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "status": "blocked"
}

Event

[
    {
        "uuid": "019fd351-4ddd-729a-8451-42ed7f9f8e9f",
        "type": "contact_status_changed",
        "created_on": "2018-04-11T18:24:30.123456Z",
        "status": "blocked"
    },
    {
        "uuid": "019fd351-4ddd-72a1-ba12-f5edadd2bd41",
        "type": "contact_groups_changed",
        "created_on": "2018-04-11T18:24:30.123456Z",
        "groups_removed": [
            {
                "uuid": "4f1f98fc-27a7-4a69-bbdb-24744ba739a9",
                "name": "Males"
            },
            {
                "uuid": "1e1ce1e1-9288-4504-869e-022d1003c72a",
                "name": "Customers"
            }
        ]
    }
]

set_contact_timezone

Can be used to update the timezone of the contact. The timezone is a template and white space is trimmed from the final value. An empty string clears the timezone. A contact_timezone_changed event will be created with the corresponding value.

Action

{
    "type": "set_contact_timezone",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "timezone": "Africa/Kigali"
}

Event

{
    "uuid": "019fd351-4de2-7e4f-a480-34c08e788481",
    "type": "contact_timezone_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "timezone": "Africa/Kigali"
}

set_run_local

Can be used to set, increment or clear a local variable on the run - as determined by the operation field. The local will be available in the context for the run as @locals.[local]. The value field may be a template and will be evaluated.

Action

{
    "type": "set_run_local",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "local": "my_var",
    "value": "1",
    "operation": "increment"
}

Event

[]

set_run_result

Can be used to save a result for a flow. The result will be available in the context for the run as @results.[name]. The optional category can be used as a way of categorizing results, this can be useful for reporting or analytics.

Both the value and category fields may be templates. A run_result_changed event will be created with the final values.

Action

{
    "type": "set_run_result",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "name": "Gender",
    "value": "m",
    "category": "Male"
}

Event

{
    "uuid": "019fd351-4de3-7e13-a0ef-929154b7d563",
    "type": "run_result_changed",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "name": "Gender",
    "value": "m",
    "category": "Male"
}

start_session

Can be used to trigger sessions for other contacts and groups. A session_triggered event will be created and it’s the responsibility of the caller to act on that by initiating a new session with the flow engine.

Action

{
    "type": "start_session",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "groups": [
        {
            "uuid": "1e1ce1e1-9288-4504-869e-022d1003c72a",
            "name": "Customers"
        }
    ],
    "flow": {
        "uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
        "name": "Registration"
    },
    "exclusions": {
        "in_a_flow": true
    }
}

Event

{
    "uuid": "019fd351-4de4-777f-95ef-e4990cac10a0",
    "type": "session_triggered",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "flow": {
        "uuid": "b7cf0d83-f1c9-411c-96fd-c511a4cfa86d",
        "name": "Collect Age"
    },
    "groups": [
        {
            "uuid": "1e1ce1e1-9288-4504-869e-022d1003c72a",
            "name": "Customers"
        }
    ],
    "exclusions": {
        "in_a_flow": true
    },
    "run_summary": {
        "uuid": "019fd351-4db9-753a-95cf-9fca95f1c30a",
        "flow": {
            "uuid": "50c3706e-fedb-42c0-8eab-dda3335714b7",
            "name": "Registration",
            "revision": 123
        },
        "contact": {
            "uuid": "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f",
            "id": 1234567,
            "name": "Bob Smith",
            "language": "eng",
            "status": "blocked",
            "timezone": "Africa/Kigali",
            "created_on": "2018-06-20T11:40:30.123456789Z",
            "last_seen_on": "2017-12-31T11:35:09.123456789Z",
            "urns": [
                "tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d",
                "twitterid:54784326227#nyaruka",
                "mailto:foo@bar.com",
                "tel:+12344563452"
            ],
            "fields": {
                "activation_token": {
                    "text": "AACC55"
                },
                "age": {
                    "text": "23",
                    "number": 23
                },
                "gender": {
                    "text": "Female"
                },
                "join_date": {
                    "text": "2017-12-02",
                    "datetime": "2017-12-02T00:00:00.000000-02:00"
                }
            }
        },
        "status": "completed",
        "results": {
            "2factor": {
                "name": "2Factor",
                "value": "34634624463525",
                "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                "created_on": "2018-04-11T18:24:30.123456Z"
            },
            "favorite_color": {
                "name": "Favorite Color",
                "value": "red",
                "category": "Red",
                "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                "created_on": "2018-04-11T18:24:30.123456Z"
            },
            "phone_number": {
                "name": "Phone Number",
                "value": "+12344563452",
                "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                "created_on": "2018-04-11T18:24:30.123456Z"
            },
            "webhook": {
                "name": "webhook",
                "value": "200",
                "category": "Success",
                "node_uuid": "f5bb9b7a-7b5e-45c3-8f0e-61b4e95edf03",
                "input": "GET http://127.0.0.1:49998/?content=%7B%22results%22%3A%5B%7B%22state%22%3A%22WA%22%7D%2C%7B%22state%22%3A%22IN%22%7D%5D%7D",
                "extra": {
                    "results": [
                        {
                            "state": "WA"
                        },
                        {
                            "state": "IN"
                        }
                    ]
                },
                "created_on": "2018-04-11T18:24:30.123456Z"
            }
        }
    },
    "history": {
        "parent_uuid": "019fd351-4db9-7229-924e-9de1a11831b3",
        "ancestors": 1,
        "ancestors_since_input": 0
    }
}

transfer_airtime

Attempts to make an airtime transfer to the contact, using their first phone URN as the recipient.

An airtime_created event will be created if the airtime transfer could be initiated. The action sets a _new_transfer local to the UUID of that event when the transfer is initiated, and to an empty string otherwise.

Action

{
    "type": "transfer_airtime",
    "uuid": "8eebd020-1af5-431c-b943-aa670fc74da9",
    "amounts": {
        "RWF": 500,
        "USD": 0.5
    }
}

Event

{
    "uuid": "019fd351-4de5-7024-9cb6-5bee17d660e7",
    "type": "airtime_created",
    "created_on": "2018-04-11T18:24:30.123456Z",
    "external_id": "8BT9MFYCJP",
    "sender": "tel:+17036975131",
    "recipient": "tel:+12024561111",
    "currency": "RWF",
    "amount": 500,
    "http_logs": [
        {
            "url": "http://send.airtime.com",
            "status_code": 200,
            "request": "GET / HTTP/1.1\r\nHost: send.airtime.com\r\nUser-Agent: Go-http-client/1.1\r\nAccept-Encoding: gzip\r\n\r\n",
            "response": "HTTP/1.0 200 OK\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}",
            "elapsed_ms": 0,
            "retries": 0,
            "sizes": {
                "request": 0,
                "response": 0
            },
            "status": "success",
            "created_on": "2019-10-16T13:59:30.123456789Z"
        }
    ]
}