I'm working on a node.js facebook messenger bot and I need to store the user response from a message the bot sends to be called later, presumably through the use of a variable.
// defines that 'text' is any message sent by the user
let text = event.message.text
// if the user's text contains 'Savings', 'saving', 'calculator', or 'Calculator, the following conditions will occur:
if (text.search("Saving") >= 0 || text.search("saving") >= 0 || text.search("Calculator") >= 0 || text.search("calculator") >= 0) {
sendTextMessage(sender, "How much would you like to save?");
// here is where I want to store the response to how much money the user wants to save
}
Any help would be very much appreciated!
The simplest thing to do would be to store it in an object with the PSID as key:
let cache[psid] = value;
The problem with using a variable is that it isn't particularly stable. If the node process crashes you lose your cache. You should ideally use an external key value store. Redis is an option that's super easy to get up and running.