🛑

Simple Opt Out Automation

TagsOpt Out
DescriptionA simple channel app for automatically opting out inbound responses based on keyword detection.
FeaturesJavaScript
TypeChannel

var oow = ["fin", "stop", "désabonné"];

if (store.org.optOutWords == undefined) {
   store.save("org", "optOutWords", JSON.stringify(oow));
} else {
   oow = json(store.org.optOutWords);
}

var s = message.split(" ");

for (var i = 0; i < s.length; i++) {
   var w = s[i].toLowerCase();
   
   if (oow.indexOf(w) != -1) {
      platform.whisper("Keyword detected " + w + " -- automatic opt out")
      console.log("Opt Out automation -- opting out " + store.conversation.customerChannel);
 
      platform.api.customers.updateCustomer(
         {"customerId": store.conversation.customerId},
         {"globalOptOut":true}
      );
      
      break;
   }
}