kykint

Detect normal message using regex

Showing 1 changed file with 5 additions and 5 deletions
......@@ -31,15 +31,15 @@ bot.onText(/\/echo (.+)/, (msg, match) => {
bot.sendMessage(chatId, resp);
});
// Listen for any kind of message. Translate if it's not a command.
bot.on('message', (msg) => {
// [Any normal message which is not a command (not starting with '/')]
bot.onText(/(?!\/)(.+)/, (msg, match) => {
const chatId = msg.chat.id;
const chatType = msg.chat.type;
const received_msg = msg.text;
const received_msg = match[1];
// Ignore if input is a command or we are not on a private chat,
// Ignore if we are not on a private chat,
// since direct translation is to be used only on private chats.
if (received_msg[0] == '/' || chatType != 'private') {
if (chatType != 'private') {
return;
}
......