0

Here's what I have - an outbound message with NEXT keyword functionality which is intended to capture the recipient's responses. If the recipient replies with a response that my AMPScript code does not handle, they get a response that says "Invalid response - please type Yes or No". But, at THAT point, the conversation is over and the recipient is no longer interacting with the message (because if they at that point realized they goofed up and then put the right response "Yes" or "No", they get a message that says "Keyword not recognized"). Basically, I want the conversation to continue despite them entering wrong possibilities of answers. Here's my SMS code:

%%[
var @response, @validResponse
set @response = [MSG(0).NOUNS]

if IndexOf(@response, 'yes') > 0 or IndexOf(@response, 'no') > 0 then
    set @validResponse = true
]%%

%%[ 
if @validResponse == true then
    UpsertData('Vaccine_Scheduler_Text_Responses', 1, 'MobileNumber', MOBILE_NUMBER, 'InitialResponse', @response)

    if IndexOf(@response, 'no') > 0 then 
    /*UpdateSingleSalesforceObject('Account', ID of object to update, appointment preference, 'Appt no longer needed')
      UpdateSingleSalesforceObject('Account', ID of object to update, 'No_Longer_Wants_Vaccine__c', TRUE)*/
]%%
    Thank you for your reply. You have reported that you no longer need an appointment. We kindly ask that you provide a reason by replying to this message with one of the numbers below.
    1 - Already Received COVID-19 Vaccine Elsewhere
    2 - Obtained COVID-19 Vaccine Appointment Elsewhere
    3 - No Longer Wish to be Vaccinated
%%[ 
    endif 
]%%

%%[  
    if IndexOf(@response, 'yes') > 0 then
      /*UpdateSingleSalesforceObject('Account', ID of object to update, appointment preference, 'Need an appointment')*/
]%%

Thank you for your reply. You will receive an appointment confirmation when you are matched with an available appointment. If at any point you would like to change your response, you may do so from the View/Cancel Appointments screen in the TPHVS.

%%[ endif ]%%
%%[ endif ]%%
%%[ else ]%%
Your response is invalid. Please reply 'yes' or 'no'.
%%[ endif ]%%
1
  • This seems undoable, because ampscript does not support a do while loop. The only thing I can think of now, is defining the no. of wrong responses you can allow the customers(say 5), is you can iterate through your whole code 5 times, each time checking the response.(not sure, if this is something that serves your business requirement) May 12, 2021 at 9:21

1 Answer 1

1

Use the CreateSMSConversation function - it will allow to continue the exchange with the contact under a specified keyword (like the "next keyword" function in the interface).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .