M
M
Mixa2017-07-12 10:31:50
PHP
Mixa, 2017-07-12 10:31:50

Why is $bot->run(); used in telegram?

Actually, subject. After all, if I use the $bot->sendMessage or $bot->sendPhoto function, then everything works anyway. What function does $bot->run(); then perform?
And if it is necessary, then in the case when I have several teams in a row, put wounds after each or after the last team?
Update . I use https://github.com/TelegramBot/Api

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2017-07-12
@Mixa

You can look at the source code and find the run() method

/**
     * Webhook handler
     *
     * @return array
     * @throws \TelegramBot\Api\InvalidJsonException
     */
    public function run()
    {
        if ($data = BotApi::jsonValidate($this->getRawBody(), true)) {
            $this->handle([Update::fromResponse($data)]);
        }
    }

As you can see, this method looks to see if valid JSON data came with the request and tries to process the incoming request. Those. this method is needed to process incoming requests to the bot.
To send messages not in response to an incoming message, but initiated somehow else, for example, by a timer or simply by running a script from the command line, you do not need to wait for incoming requests.

A
Anton, 2017-07-12
Reytarovsky @Antonchik

To start a bot and receive messages from it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question