2017-09-11 11 views
0

私はnode.jsのFacebookブックメッセンジャーボットに取り組んでいます。ボットが後で呼び出すために送信するメッセージからユーザー応答を保存する必要があります。変数。変数にユーザーの応答を保存する - facebook messenger bot js

// 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 
} 

ご協力いただければ幸いです。

答えて

0

最も簡単な方法は、キーとしてPSIDを持つオブジェクトに保管するために、次のようになります。

let cache[psid] = value;

変数を使用しての問題点は、特に安定していないということです。ノードプロセスがクラッシュすると、キャッシュが失われます。理想的には、外部キー値ストアを使用する必要があります。 Redisは、起動して実行するのが簡単なオプションです。

+0

受信者から送信された次のテキストを保存する方法を理解できません。 – sickguy125

+0

例えば、保存する必要がある金額を尋ねて、「125」と回答した場合、受信者が次に送信するテキストは「125」であると判断できるようにする必要があります。 – sickguy125

+0

オブジェクトの場合は、以前の値を上書きします。 let messages = {}; メッセージ[user_psid] = 125 console.log(message [user_psid])// 125 メッセージ[user_psid] = "新しい値" console.log(message [user_psid])//新しい値 – amuramoto

関連する問題