From 32a76cf01551a8f252536bb04f538bfe9a6386fd Mon Sep 17 00:00:00 2001 From: Krishan Goyal Date: Thu, 29 Apr 2021 09:59:00 +0530 Subject: [PATCH 1/2] Whatsapp Workflow with dummy HTTP actions --- configs/actions/wa_actions.json | 334 +++++++++++++++++++++ configs/transitions/wa_transitions.json | 366 ++++++++++++++++++++++++ configs/workflow/wa_workflow.json | 12 + 3 files changed, 712 insertions(+) create mode 100644 configs/actions/wa_actions.json create mode 100644 configs/transitions/wa_transitions.json create mode 100644 configs/workflow/wa_workflow.json diff --git a/configs/actions/wa_actions.json b/configs/actions/wa_actions.json new file mode 100644 index 00000000..b298cc38 --- /dev/null +++ b/configs/actions/wa_actions.json @@ -0,0 +1,334 @@ +[ + { + "templateId": "WA_LANGUAGE_SELECTION", + "name": "Send language selection msg", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_SEND_LANGUAGE_SELECTION_MSG" + ] + }, + { + "templateId": "WA_SEND_LANGUAGE_SELECTION_MSG", + "name": "Send language selection msg", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_LANGUAGE_AND_SEND_COVID_STATUS_MSG", + "name": "Save language and ask covid status", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_SAVE_MSG_ID", + "WA_SAVE_LANGUAGE", + "WA_ASK_COVID_STATUS" + ] + }, + { + "templateId": "WA_ASK_COVID_STATUS", + "name": "Ask covid status", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_LANGUAGE", + "name": "Save user preferred language", + "active": true, + "type": "TRANSLATOR", + "translator": "{\"language\" : \"{{dataObject.data.input}}\"}" + }, + { + "templateId": "WA_ON_COVID_NEGATIVE", + "name": "Mark Covid Negative", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_RESET_MSG_ID", + "WA_SEND_COVID_NEGATIVE_MSG" + ] + }, + { + "templateId": "WA_SEND_COVID_NEGATIVE_MSG", + "name": "Send covid Negative msg", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_RESET_MSG_ID", + "name": "Reset message id", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"whatsappObject\": {\"messageId\": \"\"} }" + }, + { + "templateId": "WA_RESTART_FLOW", + "name": "Reset Watsapp flow", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_RESET_MSG_ID", + "WA_RESET_MESSAGE" + ] + }, + { + "templateId": "WA_RESET_MESSAGE", + "name": "Send reset flow message", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_COVID_STATE", + "name": "Save Covid State", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"covidState\" : \"{{dataObject.data.input}}\"}" + }, + { + "templateId": "WA_ASK_AGE", + "name": "Ask Age", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_SAVE_MSG_ID", + "WA_ASK_AGE_MSG" + ] + }, + { + "templateId": "WA_ASK_AGE_MSG", + "name": "Ask user age", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_AGE", + "name": "Save Patient Age", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"age\" : \"{{dataObject.data.input}}\" }" + }, + { + "templateId": "WA_CHECK_COMORBIDITIES", + "name": "Check comorbidities", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_COMORBIDITIES", + "name": "Save Patient Comorbidity details", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"comorbidityStatus\" : \"{{dataObject.data.input}}\" }" + }, + { + "templateId": "WA_CHECK_FEVER", + "name": "Check fever", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_FEVER", + "name": "Save Patient Fever details", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"fever\" : \"{{dataObject.data.input}}\" }" + }, + { + "templateId": "WA_CHECK_MOTIONS", + "name": "Check motions", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_MOTIONS", + "name": "Save Patient Motions details", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"motions\" : \"{{dataObject.data.input}}\" }" + }, + { + "templateId": "WA_CHECK_BREATH", + "name": "Check motions", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_BREATH", + "name": "Save Patient Breath details", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"breath\" : \"{{dataObject.data.input}}\" }" + }, + { + "templateId": "WA_CHECK_OXYGEN", + "name": "Check motions", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SAVE_OXYGEN", + "name": "Save Patient Oxygen details", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"oxygen\" : \"{{dataObject.data.input}}\" }" + }, + { + "templateId": "WA_PATIENT_SEVERE_CONDITION", + "name": "Patient diagnosis severe", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_SAVE_MSG_ID", + "WA_SAVE_SEVERITY_SEVERE", + "WA_SEND_SEVERITY_SEVERE_MSG" + ] + }, + { + "templateId": "WA_SAVE_SEVERITY_SEVERE", + "name": "Patient diagnosis severe", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"severity\" : 3}" + }, + { + "templateId": "WA_SEND_SEVERITY_SEVERE_MSG", + "name": "Patient diagnosis severe", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_PATIENT_MODERATE_CONDITION", + "name": "Patient diagnosis moderate", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_SAVE_MSG_ID", + "WA_SAVE_SEVERITY_MODERATE", + "WA_SEND_SEVERITY_MODERATE_MSG" + ] + }, + { + "templateId": "WA_SAVE_SEVERITY_MODERATE", + "name": "Patient diagnosis moderate", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"severity\" : 2}" + }, + { + "templateId": "WA_SEND_SEVERITY_MODERATE_MSG", + "name": "Patient diagnosis moderate", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_PATIENT_MILD_CONDITION", + "name": "Patient diagnosis mild", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_SAVE_MSG_ID", + "WA_SAVE_SEVERITY_MILD", + "WA_SEND_SEVERITY_MILD_MSG" + ] + }, + { + "templateId": "WA_SAVE_SEVERITY_MILD", + "name": "Patient diagnosis mild", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"severity\" : 1}" + }, + { + "templateId": "WA_SEND_SEVERITY_MILD_MSG", + "name": "Patient diagnosis mild", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_RAISE_FRESHDESK_TICKET_AND_SEND_MSG", + "name": "Raise Freshdesk Ticket and send msg", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_RESET_MESSAGE", + "WA_SAVE_FRESHDESK_REQUEST", + "WA_RAISE_FRESHDESK_TICKET", + "WA_SEND_DOCTOR_CALL_MSG" + ] + }, + { + "templateId": "WA_SAVE_FRESHDESK_REQUEST", + "name": "Save doctor connect", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"doctor\" : 1}" + }, + { + "templateId": "WA_RAISE_FRESHDESK_TICKET", + "name": "Raise freshdesk ticket", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_SEND_DOCTOR_CALL_MSG", + "name": "Send doctor call back msg", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + }, + { + "templateId": "WA_THANK_YOU_MSG", + "name": "Send Thank you msg", + "active": true, + "type": "COMPOUND", + "actionTemplates": [ + "WA_RESET_MESSAGE", + "WA_CLOSE_TICKET", + "WA_SEND_THANK_YOU_MSG" + ] + }, + { + "templateId": "WA_CLOSE_TICKET", + "name": "Clock Ticket", + "active": true, + "type": "TRANSLATOR", + "translator": "{ \"doctor\" : 0}" + }, + { + "templateId": "WA_SEND_THANK_YOU_MSG", + "name": "Send thank you msg", + "active": true, + "type": "HTTP", + "method": "GET", + "url": "http://localhost:8080/v1/templates/workflow" + } +] \ No newline at end of file diff --git a/configs/transitions/wa_transitions.json b/configs/transitions/wa_transitions.json new file mode 100644 index 00000000..be71b21b --- /dev/null +++ b/configs/transitions/wa_transitions.json @@ -0,0 +1,366 @@ +[ + { + "id": "2_WA_SMS_SENT_TO_LANGUAGE_SELECTION", + "type": "EVALUATED", + "fromState": "SMS_SENT", + "active": true, + "rule": "path.exists(\"$.update.source\") == true && \"$.update.source\" == \"whatsapp\"", + "toState": { + "name": "WA_LANGUAGE_SELECTION", + "terminal": false + }, + "action": "WA_LANGUAGE_SELECTION" + }, + { + "id": "2_WA_LANGUAGE_SELECTION_TO_CHECK_COVID", + "type": "EVALUATED", + "fromState": "WA_LANGUAGE_SELECTION", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 7 && path.exists(\"$.update.whatsappObject.messageId\") == true && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_CHECK_COVID", + "terminal": false + }, + "action": "WA_SAVE_LANGUAGE_AND_SEND_COVID_STATUS_MSG" + }, + { + "id": "2_WA_LANGUAGE_SELECTION_AGAIN", + "type": "EVALUATED", + "fromState": "WA_LANGUAGE_SELECTION", + "active": true, + "rule": "path.exists(\"$.update.whatsappObject.messageId\") == true && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_LANGUAGE_SELECTION", + "terminal": false + }, + "action": "WA_SEND_LANGUAGE_SELECTION_MSG" + }, + { + "id": "2_WA_CHECK_COVID_TO_ASK_AGE", + "type": "EVALUATED", + "fromState": "WA_CHECK_COVID", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 3 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_SAVE_COVID_STATUS", + "terminal": false + }, + "action": "WA_SAVE_COVID_STATE" + }, + { + "id": "2_WA_SAVE_COVID_TO_ABORT", + "type": "EVALUATED", + "fromState": "WA_SAVE_COVID_STATUS", + "active": true, + "rule": "\"$.update.input\" == 3", + "toState": { + "name": "SMS_SENT", + "terminal": false + }, + "action": "WA_ON_COVID_NEGATIVE" + }, + { + "id": "2_WA_CHECK_COVID_TO_RESET", + "type": "EVALUATED", + "fromState": "WA_CHECK_COVID", + "active": true, + "rule": "\"$.update.input\" == 9 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "SMS_SENT", + "terminal": false + }, + "action": "WA_RESTART_FLOW" + }, + { + "id": "2_WA_CHECK_COVID_REPEAT", + "type": "EVALUATED", + "fromState": "WA_CHECK_COVID", + "active": true, + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_CHECK_COVID", + "terminal": false + }, + "action": "WA_ASK_COVID_STATUS" + }, + { + "id": "2_WA_SAVE_COVID_TO_ASK_AGE", + "type": "DEFAULT", + "fromState": "WA_SAVE_COVID_STATUS", + "active": true, + "toState": { + "name": "WA_ASK_AGE", + "terminal": false + }, + "action": "WA_ASK_AGE" + }, + { + "id": "2_WA_ASK_AGE_TO_SAVE_AGE", + "type": "EVALUATED", + "fromState": "WA_ASK_AGE", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 150 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_SAVE_AGE", + "terminal": false + }, + "action": "WA_SAVE_AGE" + }, + { + "id": "2_WA_ASK_AGE_AGAIN", + "type": "EVALUATED", + "fromState": "WA_ASK_AGE", + "active": true, + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_ASK_AGE", + "terminal": false + }, + "action": "WA_ASK_AGE_MSG" + }, + { + "id": "2_WA_SAVE_AGE_TO_ASK_COMORBIDITIES", + "type": "DEFAULT", + "fromState": "WA_SAVE_AGE", + "active": true, + "toState": { + "name": "WA_CHECK_COMORBIDITIES", + "terminal": false + }, + "action": "WA_CHECK_COMORBIDITIES" + }, + { + "id": "2_WA_ASK_COMORBIDITIES_TO_SAVE", + "type": "EVALUATED", + "fromState": "WA_CHECK_COMORBIDITIES", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 2 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_SAVE_COMORBIDITIES", + "terminal": false + }, + "action": "WA_SAVE_COMORBIDITIES" + }, + { + "id": "2_WA_ASK_COMORBIDITIES_AGAIN", + "type": "EVALUATED", + "fromState": "WA_CHECK_COMORBIDITIES", + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "active": true, + "toState": { + "name": "WA_CHECK_COMORBIDITIES", + "terminal": false + }, + "action": "WA_CHECK_COMORBIDITIES" + }, + { + "id": "2_WA_SAVE_COMORBIDITIES_TO_ASK_FEVER", + "type": "DEFAULT", + "fromState": "WA_SAVE_COMORBIDITIES", + "active": true, + "toState": { + "name": "WA_CHECK_FEVER", + "terminal": false + }, + "action": "WA_CHECK_FEVER" + }, + { + "id": "2_WA_ASK_FEVER_TO_SAVE", + "type": "EVALUATED", + "fromState": "WA_CHECK_FEVER", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 2 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_SAVE_FEVER", + "terminal": false + }, + "action": "WA_SAVE_FEVER" + }, + { + "id": "2_WA_ASK_FEVER_AGAIN", + "type": "EVALUATED", + "fromState": "WA_CHECK_FEVER", + "active": true, + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_CHECK_FEVER", + "terminal": false + }, + "action": "WA_CHECK_FEVER" + }, + { + "id": "2_WA_SAVE_FEVER_TO_ASK_MOTIONS", + "type": "DEFAULT", + "fromState": "WA_SAVE_FEVER", + "active": true, + "toState": { + "name": "WA_CHECK_MOTIONS", + "terminal": false + }, + "action": "WA_CHECK_MOTIONS" + }, + { + "id": "2_WA_ASK_MOTIONS_TO_SAVE", + "type": "EVALUATED", + "fromState": "WA_CHECK_MOTIONS", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 2 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_SAVE_MOTIONS", + "terminal": false + }, + "action": "WA_SAVE_MOTIONS" + }, + { + "id": "2_WA_ASK_MOTIONS_AGAIN", + "type": "EVALUATED", + "fromState": "WA_CHECK_MOTIONS", + "active": true, + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_CHECK_MOTIONS", + "terminal": false + }, + "action": "WA_CHECK_MOTIONS" + }, + { + "id": "2_WA_SAVE_MOTIONS_TO_ASK_BREATH", + "type": "DEFAULT", + "fromState": "WA_SAVE_MOTIONS", + "active": true, + "toState": { + "name": "WA_CHECK_BREATH", + "terminal": false + }, + "action": "WA_CHECK_BREATH" + }, + { + "id": "2_WA_ASK_BREATH_TO_SAVE", + "type": "EVALUATED", + "fromState": "WA_CHECK_BREATH", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 2 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_SAVE_BREATH", + "terminal": false + }, + "action": "WA_SAVE_BREATH" + }, + { + "id": "2_WA_ASK_BREATH_AGAIN", + "type": "EVALUATED", + "fromState": "WA_CHECK_BREATH", + "active": true, + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_CHECK_BREATH", + "terminal": false + }, + "action": "WA_CHECK_BREATH" + }, + { + "id": "2_WA_SAVE_BREATH_TO_ASK_OXYGEN", + "type": "DEFAULT", + "fromState": "WA_SAVE_BREATH", + "active": true, + "toState": { + "name": "WA_CHECK_OXYGEN", + "terminal": false + }, + "action": "WA_CHECK_OXYGEN" + }, + { + "id": "2_WA_ASK_OXYGEN_TO_SAVE", + "type": "EVALUATED", + "fromState": "WA_CHECK_OXYGEN", + "active": true, + "rule": "\"$.update.input\" >= 1 && \"$.update.input\" <= 3 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_COMPUTE_SEVERITY", + "terminal": false + }, + "action": "WA_SAVE_OXYGEN" + }, + { + "id": "2_WA_ASK_OXYGEN_AGAIN", + "type": "EVALUATED", + "fromState": "WA_CHECK_OXYGEN", + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "active": true, + "toState": { + "name": "WA_CHECK_OXYGEN", + "terminal": false + }, + "action": "WA_CHECK_OXYGEN" + }, + { + "id": "2_WA_COMPUTE_SEVERITY_TO_TRIAGE_SEVERE", + "type": "EVALUATED", + "fromState": "WA_COMPUTE_SEVERITY", + "active": true, + "rule": "\"$.data.oxygen\" == 3", + "toState": { + "name": "WA_FINAL_RESPONSE_SENT", + "terminal": false + }, + "action": "WA_PATIENT_SEVERE_CONDITION" + }, + { + "id": "2_WA_COMPUTE_SEVERITY_TO_TRIAGE_MODERATE", + "type": "EVALUATED", + "fromState": "WA_COMPUTE_SEVERITY", + "active": true, + "rule": "\"$.data.oxygen\" == 2 && (\"$.data.comorbidityStatus\" == 1 || \"$.data.age\" > 60)", + "toState": { + "name": "WA_FINAL_RESPONSE_SENT", + "terminal": false + }, + "action": "WA_PATIENT_MODERATE_CONDITION" + }, + { + "id": "2_WA_COMPUTE_SEVERITY_TO_TRIAGE_MILD", + "type": "DEFAULT", + "fromState": "WA_COMPUTE_SEVERITY", + "active": true, + "toState": { + "name": "WA_FINAL_RESPONSE_SENT", + "terminal": false + }, + "action": "WA_PATIENT_MILD_CONDITION" + }, + { + "id": "2_WA_FINAL_RESPONSE_SENT_TO_RAISE_TICKET", + "type": "EVALUATED", + "fromState": "WA_FINAL_RESPONSE_SENT", + "active": true, + "rule": "\"$.update.input\" == 1 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "SMS_SENT", + "terminal": false + }, + "action": "WA_RAISE_FRESHDESK_TICKET_AND_SEND_MSG" + }, + { + "id": "2_WA_FINAL_RESPONSE_SENT_TO_ABORT", + "type": "EVALUATED", + "fromState": "WA_FINAL_RESPONSE_SENT", + "active": true, + "rule": "\"$.update.input\" == 2 && \"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "SMS_SENT", + "terminal": false + }, + "action": "WA_THANK_YOU_MSG" + }, + { + "id": "2_WA_FINAL_RESPONSE_SENT_REPEAT", + "type": "EVALUATED", + "fromState": "WA_FINAL_RESPONSE_SENT", + "active": true, + "rule": "\"$.update.whatsappObject.messageId\" != \"$.data.whatsappObject.messageId\"", + "toState": { + "name": "WA_COMPUTE_SEVERITY", + "terminal": false + } + } +] \ No newline at end of file diff --git a/configs/workflow/wa_workflow.json b/configs/workflow/wa_workflow.json new file mode 100644 index 00000000..befb32fe --- /dev/null +++ b/configs/workflow/wa_workflow.json @@ -0,0 +1,12 @@ +{ + "id": "6294a243-db91-41c1-85ca-f93c3e38d52f", + "name": "WA_AUTO_TRIAGE", + "active": true, + "rules": [ + "\"$.wfSource\" == \"fd\" && \"$.state\" == \"karnataka\" && \"$.flowType\" == \"fd_hi\" " + ], + "startState": { + "name": "SMS_SENT", + "terminal": false + } +} \ No newline at end of file From 7c06c41a6f34f007c498c9ea03ff14235d089728 Mon Sep 17 00:00:00 2001 From: Krishan Goyal Date: Fri, 30 Apr 2021 22:10:44 +0530 Subject: [PATCH 2/2] Whatsapp actions --- configs/actions/wa_actions.json | 156 +++++++++++++----- configs/transitions/wa_transitions.json | 2 +- .../statesman/publisher/http/HttpUtil.java | 80 ++++++--- 3 files changed, 172 insertions(+), 66 deletions(-) diff --git a/configs/actions/wa_actions.json b/configs/actions/wa_actions.json index b298cc38..3a8aee73 100644 --- a/configs/actions/wa_actions.json +++ b/configs/actions/wa_actions.json @@ -1,6 +1,6 @@ [ { - "templateId": "WA_LANGUAGE_SELECTION", + "templateId": "WA_WELCOME", "name": "Send language selection msg", "active": true, "type": "COMPOUND", @@ -8,13 +8,25 @@ "WA_SEND_LANGUAGE_SELECTION_MSG" ] }, + { + "templateId": "WA_WELCOME_MSG", + "name": "Send welcome msg", + "active": true, + "type": "HTTP", + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Welcome to COVID National Helpline. \\n \\nPlease answer the questions appropriately to receive assistance\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" + }, { "templateId": "WA_SEND_LANGUAGE_SELECTION_MSG", "name": "Send language selection msg", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Welcome to COVID National Helpline. \\n \\nPlease answer the questions appropriately to receive assistance. \\n \\n \\nPlease select language \\nType 1 πŸ‘‰ English\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_LANGUAGE_AND_SEND_COVID_STATUS_MSG", @@ -27,13 +39,25 @@ "WA_ASK_COVID_STATUS" ] }, + { + "templateId": "WA_SEND_LANGUAGE_CONFIRMATION_MSG", + "name": "Send language confirmation msg", + "active": true, + "type": "HTTP", + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Thank you for selecting the language, please answer the questions which follow.\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" + }, { "templateId": "WA_ASK_COVID_STATUS", "name": "Ask covid status", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Thank you for selecting the language, please answer the questions which follow.\\n\\n\\nAre you Covid Positive or have coronavirus related symptoms \\n\\nType 1 πŸ‘‰πŸΌ If you have been tested for Covid and your report is positive \\n\\nType 2 πŸ‘‰πŸΌ If you have coronavirus related symptoms, but have not tested/ waiting for report\\n\\nType 3 πŸ‘‰πŸΌ If you don’t have coronavirus related symptoms\\n\\nType 9 πŸ‘‰ If you want to change language\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_LANGUAGE", @@ -57,8 +81,10 @@ "name": "Send covid Negative msg", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Since you don’t have any signs of Coronavirus, we will discontinue the conversation.\\n\\nPlease follow hygiene and social distancing. Call us if you suspect any symptoms. Thank you for contacting Stepone Helpline 97456-97456\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_RESET_MSG_ID", @@ -74,17 +100,9 @@ "type": "COMPOUND", "actionTemplates": [ "WA_RESET_MSG_ID", - "WA_RESET_MESSAGE" + "WA_WELCOME" ] }, - { - "templateId": "WA_RESET_MESSAGE", - "name": "Send reset flow message", - "active": true, - "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" - }, { "templateId": "WA_SAVE_COVID_STATE", "name": "Save Covid State", @@ -107,8 +125,10 @@ "name": "Ask user age", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"What is your age? \\n\\nYou can type a number and send it. \\n\\nEx - 30, if your are 30 years old\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_AGE", @@ -122,8 +142,10 @@ "name": "Check comorbidities", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Do you have any comorbidities such as diabetes, hypertension, heart disease, HIV or cancer?\\n\\nType 1 πŸ‘‰πŸΌ Yes, or\\nType 2 πŸ‘‰πŸΌ No\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_COMORBIDITIES", @@ -137,8 +159,10 @@ "name": "Check fever", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Do you have persistent high fever, like greater than 101 for 3 or more days? \\n\\nType 1 πŸ‘‰ Yes, or, \\nType 2 πŸ‘‰ No\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_FEVER", @@ -152,8 +176,10 @@ "name": "Check motions", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Do you have loose motions, like more than 4 times a day? \\n\\nType 1 πŸ‘‰ Yes, or, \\nType 2 πŸ‘‰ No\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_MOTIONS", @@ -167,8 +193,10 @@ "name": "Check motions", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Are you having shortness of breath apart from dry cough, or fever? \\n\\nType 1 πŸ‘‰ Yes, or, \\nType 2 πŸ‘‰ No\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_BREATH", @@ -182,8 +210,10 @@ "name": "Check motions", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"What is your oxygen level? \\n\\nType 1 πŸ‘‰ if it is more than 95, or, \\nType 2 πŸ‘‰ if it is between 92 to 94, or, \\nType 3 πŸ‘‰ if it is less than 92\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_SAVE_OXYGEN", @@ -200,7 +230,7 @@ "actionTemplates": [ "WA_SAVE_MSG_ID", "WA_SAVE_SEVERITY_SEVERE", - "WA_SEND_SEVERITY_SEVERE_MSG" + "WA_SEND_CONTACT_DOCTOR_MSG" ] }, { @@ -211,12 +241,24 @@ "translator": "{ \"severity\" : 3}" }, { - "templateId": "WA_SEND_SEVERITY_SEVERE_MSG", + "templateId": "WA_SEND_SEVERITY_SEVERE_MEDICAL_ATTENTION", "name": "Patient diagnosis severe", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Your symptoms are severe \\n\\nYou need medical attention immediately in hospital with ICU support.\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" + }, + { + "templateId": "WA_SEND_CONTACT_DOCTOR_MSG", + "name": "Patient diagnosis severe", + "active": true, + "type": "HTTP", + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Your symptoms are severe \\n\\nYou need medical attention immediately in hospital with ICU support.\\n\\n\\nType 1 πŸ‘‰ If you wish to speak to a doctor,\\nType 2 πŸ‘‰ if you want to end this conversation\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_PATIENT_MODERATE_CONDITION", @@ -226,7 +268,7 @@ "actionTemplates": [ "WA_SAVE_MSG_ID", "WA_SAVE_SEVERITY_MODERATE", - "WA_SEND_SEVERITY_MODERATE_MSG" + "WA_SEND_SEVERITY_MODERATE_MEDICAL_ATTENTION" ] }, { @@ -241,8 +283,20 @@ "name": "Patient diagnosis moderate", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Your symptoms are Mild \\n\\nThings to take care of -\\n1) Keep track of the oxygen level at regular intervals.\\n2)Take the 6 minute walk test(3 times a day or when you feel uneasy), if your oxygen level falls more than 4 points during this test, please speak to your doctor immediately. Your condition can deteriorate in coming days \\n3)Please avoid contact with any of your family members and follow strict hygiene.\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" + }, + { + "templateId": "WA_SEND_SEVERITY_MODERATE_MEDICAL_ATTENTION", + "name": "Patient diagnosis moderate", + "active": true, + "type": "HTTP", + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Your symptoms are Mild \\n\\nThings to take care of -\\n1) Keep track of the oxygen level at regular intervals.\\n2)Take the 6 minute walk test(3 times a day or when you feel uneasy), if your oxygen level falls more than 4 points during this test, please speak to your doctor immediately. Your condition can deteriorate in coming days \\n3)Please avoid contact with any of your family members and follow strict hygiene.\\n\\n\\nIn future - Consult a doctor, and hospitalisation might be required in future \\n\\nYou are prescribed to take the following texts -1) Complete Hemogram (CBC), CRP\\n2)D-Dimer, LDH, Serum Ferritin\\n\\n\\nType 1 πŸ‘‰ If you wish to speak to a doctor,\\nType 2 πŸ‘‰ if you want to end this conversation\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_PATIENT_MILD_CONDITION", @@ -252,7 +306,7 @@ "actionTemplates": [ "WA_SAVE_MSG_ID", "WA_SAVE_SEVERITY_MILD", - "WA_SEND_SEVERITY_MILD_MSG" + "WA_SEND_SEVERITY_MILD_MEDICAL_ATTENTION" ] }, { @@ -267,8 +321,20 @@ "name": "Patient diagnosis mild", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Your symptoms are Mild \\n\\nThings to take care of -\\n1) Keep track of the oxygen level at regular intervals.\\n2)Take the 6 minute walk test(3 times a day or when you feel uneasy), if your oxygen level falls more than 4 points during this test, please speak to your doctor immediately. Your condition can deteriorate in coming days \\n3)Please avoid contact with any of your family members and follow strict hygiene.\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" + }, + { + "templateId": "WA_SEND_SEVERITY_MILD_MEDICAL_ATTENTION", + "name": "Patient diagnosis mild", + "active": true, + "type": "HTTP", + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Your symptoms are Mild \\n\\nThings to take care of -\\n1) Keep track of the oxygen level at regular intervals.\\n2)Take the 6 minute walk test(3 times a day or when you feel uneasy), if your oxygen level falls more than 4 points during this test, please speak to your doctor immediately. Your condition can deteriorate in coming days \\n3)Please avoid contact with any of your family members and follow strict hygiene.\\n\\n\\nYou might need medical attention if - \\n1)Difficulty in breathing \\n2)Fever/ severe cough \\n3)Oxygen level drops more than 4 points in the 6 min walk test.\\n\\n\\nType 1 πŸ‘‰ If you wish to speak to a doctor,\\nType 2 πŸ‘‰ if you want to end this conversation\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_RAISE_FRESHDESK_TICKET_AND_SEND_MSG", @@ -276,7 +342,6 @@ "active": true, "type": "COMPOUND", "actionTemplates": [ - "WA_RESET_MESSAGE", "WA_SAVE_FRESHDESK_REQUEST", "WA_RAISE_FRESHDESK_TICKET", "WA_SEND_DOCTOR_CALL_MSG" @@ -302,8 +367,10 @@ "name": "Send doctor call back msg", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Our doctor will call you today. Please keep your phone charged and next to you.\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" }, { "templateId": "WA_THANK_YOU_MSG", @@ -311,7 +378,6 @@ "active": true, "type": "COMPOUND", "actionTemplates": [ - "WA_RESET_MESSAGE", "WA_CLOSE_TICKET", "WA_SEND_THANK_YOU_MSG" ] @@ -328,7 +394,9 @@ "name": "Send thank you msg", "active": true, "type": "HTTP", - "method": "GET", - "url": "http://localhost:8080/v1/templates/workflow" + "method": "POST", + "url": "https://api.kaleyra.io/v1/SSID/messages", + "payload": "{\"to\":\"+91TO_PHONE\",\"body\":\"Thank you\",\"sender\":\"+91FROM_PHONE\",\"channel\":\"WhatsApp\",\"from\":\"+91FROM_PHONE\",\"type\":\"text\"}", + "headers": "api-key:APIKEY" } ] \ No newline at end of file diff --git a/configs/transitions/wa_transitions.json b/configs/transitions/wa_transitions.json index be71b21b..557a772d 100644 --- a/configs/transitions/wa_transitions.json +++ b/configs/transitions/wa_transitions.json @@ -9,7 +9,7 @@ "name": "WA_LANGUAGE_SELECTION", "terminal": false }, - "action": "WA_LANGUAGE_SELECTION" + "action": "WA_WELCOME" }, { "id": "2_WA_LANGUAGE_SELECTION_TO_CHECK_COVID", diff --git a/statesman-publisher/src/main/java/io/appform/statesman/publisher/http/HttpUtil.java b/statesman-publisher/src/main/java/io/appform/statesman/publisher/http/HttpUtil.java index 4bfdc7ba..25716828 100644 --- a/statesman-publisher/src/main/java/io/appform/statesman/publisher/http/HttpUtil.java +++ b/statesman-publisher/src/main/java/io/appform/statesman/publisher/http/HttpUtil.java @@ -11,7 +11,9 @@ import okhttp3.OkHttpClient; import okhttp3.Response; +import javax.net.ssl.*; import java.io.IOException; +import java.security.cert.CertificateException; import java.util.concurrent.TimeUnit; /** @@ -25,33 +27,69 @@ public static OkHttpClient defaultClient(final String clientName, final MetricRegistry registry, final HttpClientConfiguration configuration) { - int connections = configuration.getConnections(); - connections = connections == 0 ? 10 : connections; - int idleTimeOutSeconds = configuration.getIdleTimeOutSeconds(); - idleTimeOutSeconds = idleTimeOutSeconds == 0 ? 30 : idleTimeOutSeconds; + try { + // Create a trust manager that does not validate certificate chains + final TrustManager[] trustAllCerts = new TrustManager[] { + new X509TrustManager() { + @Override + public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { + } + + @Override + public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { + } + + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return new java.security.cert.X509Certificate[]{}; + } + } + }; + + // Install the all-trusting trust manager + final SSLContext sslContext = SSLContext.getInstance("SSL"); + sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); + // Create an ssl socket factory with our all-trusting manager + final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); - int connTimeout = configuration.getConnectTimeoutMs(); - connTimeout = connTimeout == 0 ? 10000 : connTimeout; + int connections = configuration.getConnections(); + connections = connections == 0 ? 10 : connections; - int opTimeout = configuration.getOpTimeoutMs(); - opTimeout = opTimeout == 0 ? 10000 : opTimeout; + int idleTimeOutSeconds = configuration.getIdleTimeOutSeconds(); + idleTimeOutSeconds = idleTimeOutSeconds == 0 ? 30 : idleTimeOutSeconds; - final Dispatcher dispatcher = new Dispatcher(); - dispatcher.setMaxRequests(connections); - dispatcher.setMaxRequestsPerHost(connections); + int connTimeout = configuration.getConnectTimeoutMs(); + connTimeout = connTimeout == 0 ? 10000 : connTimeout; - final OkHttpClient.Builder clientBuilder = (new OkHttpClient.Builder()) - .connectionPool(new ConnectionPool(connections, (long) idleTimeOutSeconds, TimeUnit.SECONDS)) - .connectTimeout((long) connTimeout, TimeUnit.MILLISECONDS) - .readTimeout((long) opTimeout, TimeUnit.MILLISECONDS) - .writeTimeout((long) opTimeout, TimeUnit.MILLISECONDS) - .dispatcher(dispatcher); + int opTimeout = configuration.getOpTimeoutMs(); + opTimeout = opTimeout == 0 ? 10000 : opTimeout; - return registry != null - ? InstrumentedOkHttpClients.create( - registry, clientBuilder.build(), clientName + System.currentTimeMillis()) - : clientBuilder.build(); + final Dispatcher dispatcher = new Dispatcher(); + dispatcher.setMaxRequests(connections); + dispatcher.setMaxRequestsPerHost(connections); + + final OkHttpClient.Builder clientBuilder = (new OkHttpClient.Builder()) + .connectionPool(new ConnectionPool(connections, (long) idleTimeOutSeconds, TimeUnit.SECONDS)) + .connectTimeout((long) connTimeout, TimeUnit.MILLISECONDS) + .readTimeout((long) opTimeout, TimeUnit.MILLISECONDS) + .writeTimeout((long) opTimeout, TimeUnit.MILLISECONDS) + .dispatcher(dispatcher) + .sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]) + .hostnameVerifier(new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + + return registry != null + ? InstrumentedOkHttpClients.create( + registry, clientBuilder.build(), clientName + System.currentTimeMillis()) + : clientBuilder.build(); + } catch (Exception e) { + throw new RuntimeException(e); + } } public static String body(Response response) {