Last active
June 21, 2022 15:22
-
-
Save druv5319/c653a7f2d41516142317525899ec18d3 to your computer and use it in GitHub Desktop.
Twilio Studio SMS flow to find and contact your local representatives with a given address.
This file contains hidden or 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": "SMS flow to find and contact your local representatives with a given address.", | |
| "states": [ | |
| { | |
| "name": "Trigger", | |
| "type": "trigger", | |
| "transitions": [ | |
| { | |
| "next": "main_menu", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "incomingCall" | |
| }, | |
| { | |
| "event": "incomingConversationMessage" | |
| }, | |
| { | |
| "event": "incomingRequest" | |
| }, | |
| { | |
| "event": "incomingParent" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 0, | |
| "y": 0 | |
| } | |
| } | |
| }, | |
| { | |
| "name": "main_menu", | |
| "type": "send-and-wait-for-reply", | |
| "transitions": [ | |
| { | |
| "next": "find_representative", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "timeout" | |
| }, | |
| { | |
| "event": "deliveryFailure" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": -690, | |
| "y": 210 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "body": "Hello! Looking to find and contact your local representatives? Enter your address.", | |
| "timeout": "3600" | |
| } | |
| }, | |
| { | |
| "name": "find_representative", | |
| "type": "run-function", | |
| "transitions": [ | |
| { | |
| "next": "reply_with_representatives", | |
| "event": "success" | |
| }, | |
| { | |
| "next": "invalid_address", | |
| "event": "fail" | |
| } | |
| ], | |
| "properties": { | |
| "service_sid": "default", | |
| "environment_sid": "", | |
| "offset": { | |
| "x": -300, | |
| "y": 190 | |
| }, | |
| "function_sid": "", | |
| "parameters": [ | |
| { | |
| "value": "{{widgets.main_menu.inbound.Body}}", | |
| "key": "address" | |
| } | |
| ], | |
| "url": "" | |
| } | |
| }, | |
| { | |
| "name": "reply_with_representatives", | |
| "type": "send-and-wait-for-reply", | |
| "transitions": [ | |
| { | |
| "next": "main_menu_or_view_contact", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "timeout" | |
| }, | |
| { | |
| "event": "deliveryFailure" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 100, | |
| "y": 200 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "body": "{{widgets.find_representative.parsed.smsResponse}}", | |
| "timeout": "3600" | |
| } | |
| }, | |
| { | |
| "name": "main_menu_or_view_contact", | |
| "type": "split-based-on", | |
| "transitions": [ | |
| { | |
| "next": "invalid_input_1", | |
| "event": "noMatch" | |
| }, | |
| { | |
| "next": "check_and_set_input", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If value is a number", | |
| "arguments": [ | |
| "{{widgets.reply_with_representatives.inbound.Body | downcase}}" | |
| ], | |
| "type": "regex", | |
| "value": "^\\d+$" | |
| } | |
| ] | |
| }, | |
| { | |
| "next": "main_menu", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If value is 'menu'", | |
| "arguments": [ | |
| "{{widgets.reply_with_representatives.inbound.Body | downcase}}" | |
| ], | |
| "type": "equal_to", | |
| "value": "menu" | |
| } | |
| ] | |
| } | |
| ], | |
| "properties": { | |
| "input": "{{widgets.reply_with_representatives.inbound.Body | downcase}}", | |
| "offset": { | |
| "x": 110, | |
| "y": 390 | |
| } | |
| } | |
| }, | |
| { | |
| "name": "invalid_input_1", | |
| "type": "send-message", | |
| "transitions": [ | |
| { | |
| "next": "reply_with_representatives", | |
| "event": "sent" | |
| }, | |
| { | |
| "event": "failed" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": -90, | |
| "y": 650 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "to": "{{contact.channel.address}}", | |
| "body": "Invalid input." | |
| } | |
| }, | |
| { | |
| "name": "invalid_address", | |
| "type": "send-message", | |
| "transitions": [ | |
| { | |
| "next": "main_menu", | |
| "event": "sent" | |
| }, | |
| { | |
| "event": "failed" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": -510, | |
| "y": 470 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "to": "{{contact.channel.address}}", | |
| "body": "Invalid address. Try again." | |
| } | |
| }, | |
| { | |
| "name": "check_and_set_input", | |
| "type": "set-variables", | |
| "transitions": [ | |
| { | |
| "next": "validate_number_range", | |
| "event": "next" | |
| } | |
| ], | |
| "properties": { | |
| "variables": [ | |
| { | |
| "value": "{% assign input = widgets.reply_with_representatives.inbound.Body | plus:0 %}\n{% if input > 0 and input <= widgets.find_representative.parsed.contactInfos.size %}\n{{input}}\n{% else %}\n{{null}}\n{% endif %}", | |
| "key": "selection" | |
| } | |
| ], | |
| "offset": { | |
| "x": 590, | |
| "y": 220 | |
| } | |
| } | |
| }, | |
| { | |
| "name": "validate_number_range", | |
| "type": "split-based-on", | |
| "transitions": [ | |
| { | |
| "next": "show_contact_info", | |
| "event": "noMatch" | |
| }, | |
| { | |
| "next": "invalid_input_1", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If number is not in range", | |
| "arguments": [ | |
| "{{flow.variables.selection}}" | |
| ], | |
| "type": "is_blank", | |
| "value": "Is Blank" | |
| } | |
| ] | |
| } | |
| ], | |
| "properties": { | |
| "input": "{{flow.variables.selection}}", | |
| "offset": { | |
| "x": 600, | |
| "y": 430 | |
| } | |
| } | |
| }, | |
| { | |
| "name": "show_contact_info", | |
| "type": "send-and-wait-for-reply", | |
| "transitions": [ | |
| { | |
| "next": "show_contact_info_flow", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "timeout" | |
| }, | |
| { | |
| "event": "deliveryFailure" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 640, | |
| "y": 690 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "body": "{% assign index = flow.variables.selection | minus:1 %}{{widgets.find_representative.parsed.contactInfos[index].contactInfoString}}\nEnter 'back' to view your other local officals. {% if widgets.find_representative.parsed.contactInfos[index].email != null %}To send a message to {{widgets.find_representative.parsed.contactInfos[index].officialName}}, enter your email to proceed.{% endif %}", | |
| "timeout": "3600" | |
| } | |
| }, | |
| { | |
| "name": "show_contact_info_flow", | |
| "type": "split-based-on", | |
| "transitions": [ | |
| { | |
| "next": "invalid_input_2", | |
| "event": "noMatch" | |
| }, | |
| { | |
| "next": "reply_with_representatives", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If value equal_to back", | |
| "arguments": [ | |
| "{{widgets.show_contact_info.inbound.Body | downcase}}" | |
| ], | |
| "type": "equal_to", | |
| "value": "back" | |
| } | |
| ] | |
| }, | |
| { | |
| "next": "get_subject", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If value is an email", | |
| "arguments": [ | |
| "{{widgets.show_contact_info.inbound.Body | downcase}}" | |
| ], | |
| "type": "regex", | |
| "value": "(?:[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])" | |
| } | |
| ] | |
| } | |
| ], | |
| "properties": { | |
| "input": "{{widgets.show_contact_info.inbound.Body | downcase}}", | |
| "offset": { | |
| "x": 660, | |
| "y": 930 | |
| } | |
| } | |
| }, | |
| { | |
| "name": "get_subject", | |
| "type": "send-and-wait-for-reply", | |
| "transitions": [ | |
| { | |
| "next": "get_message", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "timeout" | |
| }, | |
| { | |
| "event": "deliveryFailure" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": -200, | |
| "y": 1290 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "body": "Enter your subject line for the email", | |
| "timeout": "3600" | |
| } | |
| }, | |
| { | |
| "name": "invalid_input_2", | |
| "type": "send-message", | |
| "transitions": [ | |
| { | |
| "next": "show_contact_info", | |
| "event": "sent" | |
| }, | |
| { | |
| "event": "failed" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": -120, | |
| "y": 940 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "to": "{{contact.channel.address}}", | |
| "body": "Invalid input" | |
| } | |
| }, | |
| { | |
| "name": "get_message", | |
| "type": "send-and-wait-for-reply", | |
| "transitions": [ | |
| { | |
| "next": "send_email_confirmation", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "timeout" | |
| }, | |
| { | |
| "event": "deliveryFailure" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 130, | |
| "y": 1290 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "body": "Enter your message", | |
| "timeout": "3600" | |
| } | |
| }, | |
| { | |
| "name": "send_email_confirmation", | |
| "type": "send-and-wait-for-reply", | |
| "transitions": [ | |
| { | |
| "next": "send_email_split", | |
| "event": "incomingMessage" | |
| }, | |
| { | |
| "event": "timeout" | |
| }, | |
| { | |
| "event": "deliveryFailure" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 450, | |
| "y": 1310 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "body": "{% assign index = flow.variables.selection | minus:1 %}\nHere is the email that will be sent to {{widgets.find_representative.parsed.contactInfos[index].officialName}}:\n\nReply to Email: {{widgets.show_contact_info.inbound.Body}}\nSubject: {{widgets.get_subject.inbound.Body}}\n\nMessage: {{widgets.get_message.inbound.Body}}\n\nTo send the email, enter 'send'. To go back, enter 'back'", | |
| "timeout": "3600" | |
| } | |
| }, | |
| { | |
| "name": "send_email_split", | |
| "type": "split-based-on", | |
| "transitions": [ | |
| { | |
| "next": "invalid_input_3", | |
| "event": "noMatch" | |
| }, | |
| { | |
| "next": "show_contact_info", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If value equal_to back", | |
| "arguments": [ | |
| "{{widgets.send_email_confirmation.inbound.Body | downcase}}" | |
| ], | |
| "type": "equal_to", | |
| "value": "back" | |
| } | |
| ] | |
| }, | |
| { | |
| "next": "send_email_function", | |
| "event": "match", | |
| "conditions": [ | |
| { | |
| "friendly_name": "If value equal_to send", | |
| "arguments": [ | |
| "{{widgets.send_email_confirmation.inbound.Body | downcase}}" | |
| ], | |
| "type": "equal_to", | |
| "value": "send" | |
| } | |
| ] | |
| } | |
| ], | |
| "properties": { | |
| "input": "{{widgets.send_email_confirmation.inbound.Body | downcase}}", | |
| "offset": { | |
| "x": 770, | |
| "y": 1300 | |
| } | |
| } | |
| }, | |
| { | |
| "name": "send_email_function", | |
| "type": "run-function", | |
| "transitions": [ | |
| { | |
| "next": "email_sent", | |
| "event": "success" | |
| }, | |
| { | |
| "next": "email_not_sent", | |
| "event": "fail" | |
| } | |
| ], | |
| "properties": { | |
| "service_sid": "default", | |
| "environment_sid": "", | |
| "offset": { | |
| "x": 1250, | |
| "y": 1300 | |
| }, | |
| "function_sid": "", | |
| "parameters": [ | |
| { | |
| "value": "{% assign index = flow.variables.selection | minus:1 %}{{widgets.find_representative.parsed.contactInfos[index].email}}", | |
| "key": "officialEmail" | |
| }, | |
| { | |
| "value": "{{widgets.get_subject.inbound.Body}}", | |
| "key": "subject" | |
| }, | |
| { | |
| "value": "{{widgets.show_contact_info.inbound.Body}}", | |
| "key": "replyToEmail" | |
| }, | |
| { | |
| "value": "{{widgets.get_message.inbound.Body}}", | |
| "key": "message" | |
| } | |
| ], | |
| "url": "" | |
| } | |
| }, | |
| { | |
| "name": "invalid_input_3", | |
| "type": "send-message", | |
| "transitions": [ | |
| { | |
| "next": "send_email_confirmation", | |
| "event": "sent" | |
| }, | |
| { | |
| "event": "failed" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 360, | |
| "y": 1650 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "to": "{{contact.channel.address}}", | |
| "body": "Invalid input" | |
| } | |
| }, | |
| { | |
| "name": "email_sent", | |
| "type": "send-message", | |
| "transitions": [ | |
| { | |
| "event": "sent" | |
| }, | |
| { | |
| "event": "failed" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 1260, | |
| "y": 1560 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "to": "{{contact.channel.address}}", | |
| "body": "Email has been sent!" | |
| } | |
| }, | |
| { | |
| "name": "email_not_sent", | |
| "type": "send-message", | |
| "transitions": [ | |
| { | |
| "next": "show_contact_info", | |
| "event": "sent" | |
| }, | |
| { | |
| "event": "failed" | |
| } | |
| ], | |
| "properties": { | |
| "offset": { | |
| "x": 1260, | |
| "y": 1040 | |
| }, | |
| "service": "{{trigger.message.InstanceSid}}", | |
| "channel": "{{trigger.message.ChannelSid}}", | |
| "from": "{{flow.channel.address}}", | |
| "to": "{{contact.channel.address}}", | |
| "body": "Email was not sent, please try again." | |
| } | |
| } | |
| ], | |
| "initial_state": "Trigger", | |
| "flags": { | |
| "allow_concurrent_calls": true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment