I'm building a texting app and I have a compliance handler that has the customer agree to my privacy policy before initiating a conversation by replying Yes, Y, or Start. After that I have set a conversation starter to initiate the conversation by saying "How can we help you". But every time the customer sends (yes, y, start) the conversation starter gets sent again. I need to have it so it only sends the conversation started when the customer has not opted in?

 var welcomeQ = true;
            if (String.Compare(incoming.Body, "YES", StringComparison.OrdinalIgnoreCase) ==0 || 
                String.Compare(incoming.Body, "Y", StringComparison.OrdinalIgnoreCase) == 0 || 
                String.Compare(incoming.Body, "START", StringComparison.OrdinalIgnoreCase) == 0)
            {
                customer.OptedIn = true;
                welcomeQ = false;
            }
            if (!welcomeQ)
            {
                var WelcomeMessage = new MessagingResponse();

                var welcomeMessage = @"How can we help you today?";
                welcomeQ = false;
                WelcomeMessage.Message(welcomeMessage);

                  return TwiML(WelcomeMessage);

            }



            //Compliance Handler
            if (!customer.OptedIn)
            {            

                var optresponse = new MessagingResponse();
                var optMessage = target_location.PrivacyPolicy.Organization + @".
Msg&data rates may apply.
Reply HELP for help, STOP to cancel.
T&C/Privacy Policy: " + target_location.PrivacyPolicy.PolicyLink +
@" Reply YES (y) to continue";
                optresponse.Message(optMessage);                
                return TwiML(optresponse);
            }

2 Answers

0
Sailesh Babu Doppalapudi On Best Solutions
         if ((String.Compare(incoming.Body, "YES", StringComparison.OrdinalIgnoreCase) ==0 || 
            String.Compare(incoming.Body, "Y", StringComparison.OrdinalIgnoreCase) == 0 || 
            String.Compare(incoming.Body, "START", StringComparison.OrdinalIgnoreCase) == 0) && 
           !customer.OptedIn)
        {
            customer.OptedIn = true;
            welcomeQ = false;
        }

You need to check if Customer already Opted In before checking if response is Y. Then it won't set welcomeQ to false

0
danninta On

At the end of your first IF you are setting welcomeQ = false. The next IF statement will run if welcomeQ = false. This will always result in the "how can we help you today?" message following the Yes, Y, Start. From what I can tell in this snippit you can remove the 7th line all together and get the result you are expecting, which will instead only give that message when something other than Yes, Y, Start is provided.