2017-05-02 7 views
0

なぜこのコードは任意の場所でユーザメッセージを取得するのか、それともどのボタンでも意味します。「node-telegram-bot-api」モジュール経由でメッセージを受信

私は、ユーザーのメッセージを受け取るでしょう。このコードで

、と私はbuttons除外とprevious buttons、私はコンソールログユーザー本物のメッセージ(ないボタンタイトルを)必要があるため、 私はContact usボタンにいるときだけ、ユーザ・メッセージを取得する必要があります。

bot.on('message', (msg) => { 
    if (!locale.keyboards[msg.text] && 
    !msg.text.includes("Previous Buttons ")) { 
    console.log("User Message is: " + msg.text) 
    const opts = { 
     reply_to_message_id: msg.message_id, 
     reply_markup: JSON.stringify({ 
     keyboard: arrangeKeyboardWithOut(locale.keyboards["/start"].childs, 2, msg), 
     resize_keyboard: true, 
     one_time_keyboard: true 
     }) 
    }; 
    bot.sendMessage(msg.chat.id, 'Received your message', opts); 
    } 
}); 

答えて

0

私は、これら2つの機能

var getmessage = async() => { 
    // Listen for any kind of message. There are different kinds of messages. 
    await new Promise((resolve, reject) => { 
    bot.on('message', (msg) => { 
     if (!locale.keyboards[msg.text] && 
     !msg.text.includes("previous button")) { 
     console.log("user message is: " + msg.text) 
     const opts = { 
      reply_to_message_id: msg.message_id, 
      reply_markup: JSON.stringify({ 
      keyboard: arrangeKeyboardWithOut(locale.keyboards["/start"].childs, 2, msg), 
      resize_keyboard: true, 
      one_time_keyboard: true 
      }) 
     }; 
     bot.sendMessage(msg.chat.id, ' your message recieved', opts); 
     } 
     resolve(true); 
    }); 
    }); 
    return 
} 

var getmessage1 = async() => { 
    await getmessage(); 
} 

は、その後、私は私のelse if

else if (msg.text == ["contact us"]) { 
     const opts = { 
     reply_to_message_id: msg.message_id, 
     reply_markup: JSON.stringify({ 
      keyboard: arrangeKeyboard(locale.keyboards[msg.text].childs, 2, msg), 
      resize_keyboard: true, 
      one_time_keyboard: true 
     }) 
     }; 
     bot.sendMessage(msg.chat.id, "Please Write your Messages:", opts); 
     getmessage1(); 
    } 
で呼び出さ集約した初
関連する問題