episphere / connect

Connect API for DCEG's Cohort Study
10 stars 5 forks source link

Programming an automated response to incoming text messages #997

Open HanaShiho opened 2 months ago

HanaShiho commented 2 months ago

In Twilio, the advanced opt-out feature primarily handles specific keyword management for opt-outs (like STOP) and opt-in(like START). This feature automatically recognises and responds to these designated keywords. Additionally, we currently have a standardized and automated response to "HELP" replies to our phone number.

We want to program an automated response to incoming messages that aren't specifically these opt-out or opt-in keywords using Twilio's Programable SMS logic.We can write a Twilio Function(serverless environment provided by Twili) to handle incoming SMS messages. This function can check the content of each message and decide what response to send. If the message doesn't contain one of our predefined keywords (e.g. HELP or STOP), the function can send a different automated response.

I've included a sample script below. This script checks if the incoming message is either "HELP" or "STOP". If not, it sends a custom response.

exports.handler = function(context, event, callback) { let incomingMsg = event.Body.trim().toUpperCase();

// Check if the message is any of the special keywords
if (incomingMsg === "HELP" || incomingMsg === "STOP") {
    // Handle standard opt-out/opt-in process
    return callback(null, "Opt-out or Help instructions here.");
} else {
    // Your custom logic for other messages
    let responseMsg = "Thank you for your message. Here's some info...";
    return callback(null, responseMsg);
}

};

@depietrodeanna can you please provide a sample automated response we'd like to use?

depietrodeanna commented 2 months ago

Automated response: "Thanks for your message. We are unable to see replies to this number. Please visit the Connect Support Center at https://myconnect.cancer.gov/support for help."