S
S
shah120072018-02-09 22:37:50
Node.js
shah12007, 2018-02-09 22:37:50

Telegram bot, how to respond if a user's message contains a keyword?

Good evening! It is necessary to make it so that the Bot, when an email address is sent to it, understands that it is email, I want to make bot.onText, if the message contains the @ symbol, please tell me the syntax, how to enter the definition in this construction only by the dog symbol bot.onText (// start/, (msg, match) => { That is, instead of start there should be a dog, but not separately, but if it is present in the text. I write on node js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2018-02-09
@shah12007

You listen to an event onMessage(or another, depending on the library you use), if there is an email in the text, you do what you have planned.
Email search by regex, working example -

/^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
.
PS //start/will not work, the "/" character must be escaped, i.e. if you want to match the word "/start", then the regex should be /\/start/.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question