J
J
JohnnyParazit2017-09-17 10:29:42
PHP
JohnnyParazit, 2017-09-17 10:29:42

How to write a value to a variable by sending a message to the telegram bot?

Here, tell me how to write a value to a variable or an array, for example:

$otvet = "";
if (strtolower($message) == 'записать слово') {
sendMsg($group_id, $otvet);
}

We write a phrase to the bot: write down the word elephant
And he puts it in the $answer variable.
How to do that!?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2017-09-17
@DmitriyEntelis

Solutions 2:
1) We send commands to the bot of the form

/write the word jiggurd

Well, accordingly, we parse the incoming message, separating the control command and the context
. I advise you to look at ready-made solutions, for example https://botman.io/
2) We send commands to the bot with two messages in a row:
/write
the word jiggurd

In this case, when receiving the first command, the bot must remember it for this user, and when receiving a message that is not a command, it must process the message in accordance with the last command (state) filled in.
The second option is a little more complicated than the first, but if the bot plans some more complex logic than a question-answer is indispensable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question