Created
December 17, 2019 13:28
-
-
Save allenheltondev/e3f35fbdba2ed41a71f79e1c8a26f64f to your computer and use it in GitHub Desktop.
Twilio Flow state machine that calls out to a REST service for logic and notifies the user of a response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "My Christmas Gift Flow", | |
"states": [ | |
{ | |
"name": "Trigger", | |
"type": "InitialState", | |
"properties": { | |
"offset": { | |
"x": 380, | |
"y": 70 | |
}, | |
"flow_url": "<Replace me with your flow url>" | |
}, | |
"transitions": [ | |
{ | |
"event": "incomingMessage", | |
"conditions": [], | |
"next": "FF8901c6f41904230f1816ef64a196f012", | |
"uuid": "99a044d8-1936-48bb-9529-2c4dd106611d" | |
}, | |
{ | |
"event": "incomingCall", | |
"conditions": [], | |
"next": "FF2a829e9b43ea56c1c39980490f3f23d0", | |
"uuid": "a57a6754-1f87-4571-9499-66844b1a17fc" | |
}, | |
{ | |
"event": "incomingRequest", | |
"conditions": [], | |
"next": null, | |
"uuid": "b127f2ae-f150-4961-a22d-19eba08aff6a" | |
} | |
], | |
"sid": "FF59b13642db03f718b386e8d5c518d533" | |
}, | |
{ | |
"name": "SendMessage", | |
"type": "Message", | |
"properties": { | |
"offset": { | |
"x": -250, | |
"y": 720 | |
}, | |
"body": "{{widgets.ContactService.parsed.Message}}", | |
"from": "{{flow.channel.address}}", | |
"to": "{{contact.channel.address}}", | |
"media_url": null, | |
"service": null, | |
"channel": null, | |
"attributes": null | |
}, | |
"transitions": [ | |
{ | |
"event": "sent", | |
"conditions": [], | |
"next": null, | |
"uuid": "39be6a15-9601-44f0-8c12-e988871db098" | |
}, | |
{ | |
"event": "failed", | |
"conditions": [], | |
"next": null, | |
"uuid": "d258a1b6-6a05-46e4-8da6-f5700a502fca" | |
} | |
], | |
"sid": "FF95d42fbb5b0470c080ca097c64fa1939" | |
}, | |
{ | |
"name": "ContactService", | |
"type": "Webhook", | |
"properties": { | |
"offset": { | |
"x": 90, | |
"y": 270 | |
}, | |
"method": "POST", | |
"url": "<Replace with your REST service Entry endpoint>", | |
"body": "{\n\"Number\": \"{{trigger.message.To}}\",\n\"Message\": \"{{trigger.message.Body}}\",\n\"ContactType\":\"TEXT\"\n}", | |
"timeout": null, | |
"parameters": null, | |
"save_response_as": null, | |
"content_type": "application/json;charset=utf-8" | |
}, | |
"transitions": [ | |
{ | |
"event": "success", | |
"conditions": [], | |
"next": "FF74e239673488b713fef2add006e7de9f", | |
"uuid": "dcf3a9a6-f1d6-4ba4-9053-ead330edec8f" | |
}, | |
{ | |
"event": "failed", | |
"conditions": [], | |
"next": null, | |
"uuid": "74ebd813-f4c0-471b-bf03-3317d1e18b37" | |
} | |
], | |
"sid": "FF8901c6f41904230f1816ef64a196f012" | |
}, | |
{ | |
"name": "ContactServiceCall", | |
"type": "Webhook", | |
"properties": { | |
"offset": { | |
"x": 430, | |
"y": 270 | |
}, | |
"method": "POST", | |
"url": "<Replace with your REST service Entry endpoint>", | |
"body": "{\n\"Number\": \"{{trigger.call.To}}\",\n\"ContactType\":\"CALL\"\n}", | |
"timeout": null, | |
"parameters": null, | |
"save_response_as": null, | |
"content_type": "application/json;charset=utf-8" | |
}, | |
"transitions": [ | |
{ | |
"event": "success", | |
"conditions": [], | |
"next": "FFd1e511a62ee68f232dd1299fd1555a8d", | |
"uuid": "be44bf3c-ee95-45eb-bc64-a3c2e5d5e513" | |
}, | |
{ | |
"event": "failed", | |
"conditions": [], | |
"next": null, | |
"uuid": "37056503-de31-4f61-9d4c-1b20ef3b6dd2" | |
} | |
], | |
"sid": "FF2a829e9b43ea56c1c39980490f3f23d0" | |
}, | |
{ | |
"name": "SayResponse", | |
"type": "SayPlay", | |
"properties": { | |
"offset": { | |
"x": 410, | |
"y": 1040 | |
}, | |
"say": "{{widgets.ContactServiceCall.parsed.Message}}", | |
"play": null, | |
"voice": "Polly.Salli", | |
"language": "en-US", | |
"loop": 1, | |
"digits": null | |
}, | |
"transitions": [ | |
{ | |
"event": "audioComplete", | |
"conditions": [], | |
"next": null, | |
"uuid": "ee10613c-0a77-40f8-a688-9eaf96e39710" | |
} | |
], | |
"sid": "FFf1e797a13eddad598fb3cfb64a8bb70e" | |
}, | |
{ | |
"name": "PlaySound", | |
"type": "SayPlay", | |
"properties": { | |
"offset": { | |
"x": 930, | |
"y": 800 | |
}, | |
"say": null, | |
"play": "{{widgets.ContactServiceCall.parsed.Sound}}", | |
"voice": null, | |
"language": null, | |
"loop": 1, | |
"digits": null | |
}, | |
"transitions": [ | |
{ | |
"event": "audioComplete", | |
"conditions": [], | |
"next": null, | |
"uuid": "7a3ad25e-1068-4343-b2e5-1790e5267fd0" | |
} | |
], | |
"sid": "FF9d2d7a78019f81030da113d6f0fe5403" | |
}, | |
{ | |
"name": "ShouldPlaySound", | |
"type": "Branch", | |
"properties": { | |
"offset": { | |
"x": 490, | |
"y": 550 | |
}, | |
"input": "{{widgets.ContactServiceCall.parsed.Sound}}" | |
}, | |
"transitions": [ | |
{ | |
"event": "noMatch", | |
"conditions": [], | |
"next": "FF3063fde1db6c0a0358a29b29728e7229", | |
"uuid": "11db0f41-0bda-49cb-b311-f729d64931d2" | |
}, | |
{ | |
"event": "match", | |
"conditions": [ | |
{ | |
"friendly_name": "ContactService.parsed.Sound", | |
"type": "is_not_blank", | |
"arguments": [ | |
"{{widgets.ContactServiceCall.parsed.Sound}}" | |
], | |
"value": "Is Not Blank" | |
} | |
], | |
"next": "FF9d2d7a78019f81030da113d6f0fe5403", | |
"uuid": "ca7961eb-8157-4e68-b876-4bd438498fe2" | |
} | |
], | |
"sid": "FFd1e511a62ee68f232dd1299fd1555a8d" | |
}, | |
{ | |
"name": "CollectDetails", | |
"type": "Branch", | |
"properties": { | |
"offset": { | |
"x": 490, | |
"y": 800 | |
}, | |
"input": "{{widgets.ContactServiceCall.parsed.Collect}}" | |
}, | |
"transitions": [ | |
{ | |
"event": "noMatch", | |
"conditions": [], | |
"next": "FFf1e797a13eddad598fb3cfb64a8bb70e", | |
"uuid": "abba7e3b-2a8d-4eff-b7f5-b1915271cccc" | |
}, | |
{ | |
"event": "match", | |
"conditions": [ | |
{ | |
"friendly_name": "If value equal_to True", | |
"type": "equal_to", | |
"arguments": [ | |
"{{widgets.ContactServiceCall.parsed.Collect}}" | |
], | |
"value": "True" | |
} | |
], | |
"next": "FF8fb7c4f4f11863a924eb975bfdaad632", | |
"uuid": "fe96aa5f-942f-4a48-8a3e-86d1dadf9625" | |
} | |
], | |
"sid": "FF3063fde1db6c0a0358a29b29728e7229" | |
}, | |
{ | |
"name": "GatherResponse", | |
"type": "Gather", | |
"properties": { | |
"offset": { | |
"x": 780, | |
"y": 1040 | |
}, | |
"timeout": 3, | |
"finish_on_key": "#", | |
"stop_gather": false, | |
"number_of_digits": null, | |
"save_response_as": null, | |
"say": "{{widgets.ContactServiceCall.parsed.Message}}", | |
"play": null, | |
"voice": "Polly.Salli", | |
"language": "en-US", | |
"loop": 1, | |
"hints": null, | |
"gather_language": "en-US", | |
"speech_timeout": null, | |
"speech_model": null, | |
"profanity_filter": null | |
}, | |
"transitions": [ | |
{ | |
"event": "keypress", | |
"conditions": [], | |
"next": null, | |
"uuid": "72dadd69-0bde-479a-b728-80672b20773b" | |
}, | |
{ | |
"event": "speech", | |
"conditions": [], | |
"next": "FFef9069abd492e11b143125105ac48d2c", | |
"uuid": "36f64f22-ccd1-45e1-9de7-af18ecfed899" | |
}, | |
{ | |
"event": "timeout", | |
"conditions": [], | |
"next": null, | |
"uuid": "e3666df4-1ee5-410a-ae97-45cb854b63da" | |
} | |
], | |
"sid": "FF8fb7c4f4f11863a924eb975bfdaad632" | |
}, | |
{ | |
"name": "GetFollowUpCall", | |
"type": "Webhook", | |
"properties": { | |
"offset": { | |
"x": 780, | |
"y": 1280 | |
}, | |
"method": "POST", | |
"url": "<Replace with your REST service Follow Up endpoint>", | |
"body": "{\n\"Number\": \"{{trigger.call.To}}\",\n\"Message\": \"{{widgets.GatherResponse.SpeechResult}}\",\n\"ContactType\":\"CALL\"\n}", | |
"timeout": null, | |
"parameters": null, | |
"save_response_as": null, | |
"content_type": "application/json;charset=utf-8" | |
}, | |
"transitions": [ | |
{ | |
"event": "success", | |
"conditions": [], | |
"next": "FFd7fa32874d841b78a436d01e9748a372", | |
"uuid": "eaadcd7f-f255-4023-8406-db330bd158bf" | |
}, | |
{ | |
"event": "failed", | |
"conditions": [], | |
"next": null, | |
"uuid": "668e51a6-958e-4e10-b7e8-8a829e7a684f" | |
} | |
], | |
"sid": "FFef9069abd492e11b143125105ac48d2c" | |
}, | |
{ | |
"name": "PlayFollowUpMessageCall", | |
"type": "SayPlay", | |
"properties": { | |
"offset": { | |
"x": 780, | |
"y": 1490 | |
}, | |
"say": "{{widgets.GetFollowUpCall.parsed.Message}}", | |
"play": null, | |
"voice": "Polly.Salli", | |
"language": "en-US", | |
"loop": 1, | |
"digits": null | |
}, | |
"transitions": [ | |
{ | |
"event": "audioComplete", | |
"conditions": [], | |
"next": null, | |
"uuid": "8e229b98-e36e-420e-bfa6-3706982cfb93" | |
} | |
], | |
"sid": "FFd7fa32874d841b78a436d01e9748a372" | |
}, | |
{ | |
"name": "ShouldFollowUp", | |
"type": "Branch", | |
"properties": { | |
"offset": { | |
"x": 80, | |
"y": 490 | |
}, | |
"input": "{{widgets.ContactService.parsed.Collect}}" | |
}, | |
"transitions": [ | |
{ | |
"event": "noMatch", | |
"conditions": [], | |
"next": "FF95d42fbb5b0470c080ca097c64fa1939", | |
"uuid": "925145b4-26bb-4e54-90fb-f6a89c01ccfc" | |
}, | |
{ | |
"event": "match", | |
"conditions": [ | |
{ | |
"friendly_name": "If value equal_to True", | |
"type": "equal_to", | |
"arguments": [ | |
"{{widgets.ContactService.parsed.Collect}}" | |
], | |
"value": "True" | |
} | |
], | |
"next": "FFfb22a86c399ad5abe0177db9c582a3a8", | |
"uuid": "8f50c677-8a86-49e7-82ac-139233664537" | |
} | |
], | |
"sid": "FF74e239673488b713fef2add006e7de9f" | |
}, | |
{ | |
"name": "GatherResponseText", | |
"type": "MessagePrompt", | |
"properties": { | |
"offset": { | |
"x": 140, | |
"y": 720 | |
}, | |
"body": "{{widgets.ContactService.parsed.Message}}", | |
"from": "{{flow.channel.address}}", | |
"timeout": 3600, | |
"save_response_as": null, | |
"media_url": null, | |
"service": "{{trigger.message.InstanceSid}}", | |
"channel": "{{trigger.message.ChannelSid}}", | |
"attributes": null | |
}, | |
"transitions": [ | |
{ | |
"event": "incomingMessage", | |
"conditions": [], | |
"next": "FF1c94117178419cdf5cfb07f2e8b12073", | |
"uuid": "c175b7b4-9e39-4bc2-ae9a-46829a581a4d" | |
}, | |
{ | |
"event": "timeout", | |
"conditions": [], | |
"next": null, | |
"uuid": "4af09a46-7271-43c2-8fab-85f8171a47cc" | |
}, | |
{ | |
"event": "deliveryFailure", | |
"conditions": [], | |
"next": null, | |
"uuid": "c4ecf37e-b6be-410c-9cd0-e772d94bbece" | |
} | |
], | |
"sid": "FFfb22a86c399ad5abe0177db9c582a3a8" | |
}, | |
{ | |
"name": "GetFollowUpText", | |
"type": "Webhook", | |
"properties": { | |
"offset": { | |
"x": -20, | |
"y": 1040 | |
}, | |
"method": "POST", | |
"url": "<Replace with your REST service Follow Up endpoint>", | |
"body": "{\n\"Number\": \"{{trigger.message.To}}\",\n\"Message\": \"{{widgets.GatherResponseText.inbound.Body}}\",\n\"ContactType\":\"TEXT\"\n}", | |
"timeout": null, | |
"parameters": null, | |
"save_response_as": null, | |
"content_type": "application/json;charset=utf-8" | |
}, | |
"transitions": [ | |
{ | |
"event": "success", | |
"conditions": [], | |
"next": "FF28d3b6f9330dbc9f5b052dd92d606e03", | |
"uuid": "27a0dcc9-06ab-4f87-8847-890601382c8f" | |
}, | |
{ | |
"event": "failed", | |
"conditions": [], | |
"next": null, | |
"uuid": "2e312e63-a40f-4a29-b5c8-ef74f4ed57f8" | |
} | |
], | |
"sid": "FF1c94117178419cdf5cfb07f2e8b12073" | |
}, | |
{ | |
"name": "SendFollowUpMessage", | |
"type": "Message", | |
"properties": { | |
"offset": { | |
"x": -20, | |
"y": 1280 | |
}, | |
"body": "{{widgets.GetFollowUpText.parsed.Message}}", | |
"from": "{{flow.channel.address}}", | |
"to": "{{contact.channel.address}}", | |
"media_url": null, | |
"service": "{{trigger.message.InstanceSid}}", | |
"channel": "{{trigger.message.ChannelSid}}", | |
"attributes": null | |
}, | |
"transitions": [ | |
{ | |
"event": "sent", | |
"conditions": [], | |
"next": null, | |
"uuid": "7b93384e-3c46-480e-9dfb-5c1fe41c4bb3" | |
}, | |
{ | |
"event": "failed", | |
"conditions": [], | |
"next": null, | |
"uuid": "8f4942a7-21c7-4325-951b-f180e3de3d8e" | |
} | |
], | |
"sid": "FF28d3b6f9330dbc9f5b052dd92d606e03" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment