C
C
CapitanFreeloader2016-07-07 11:57:14
PHP
CapitanFreeloader, 2016-07-07 11:57:14

How to set messages as read after getUpdates?

I receive messages by url, how can I set them as read after receiving them, so that they do not come again?
Google did not give an answer
Api telegram is not entirely clear

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Muhammad, 2016-07-07
@muhammad_97

Use getWebhookUpdates

S
Sergey, 2016-07-07
@VSeryoga

Add getUpdates ?offset=[update_id]
update_id - from the response, can be stored in a file or database, updating when it changes the
message will only come to those who have update_id > given

B
BoShurik, 2016-07-07
@BoShurik

You don't need to store anything. I did so

/**
 * @return void
 */
public function processUpdates()
{
    $updates = $this->api->getUpdates();
    $lastUpdateId = null;
    foreach ($updates as $update) {
        $lastUpdateId = $update->getUpdateId();
        $this->processUpdate($update);
    }
    if ($lastUpdateId) {
        $this->api->getUpdates($lastUpdateId + 1, 1);
    }
}

  1. Get a list of messages, keeping the last received id
  2. We process them
  3. Once again we get a list of messages, specifying the offset in "{last received id} + 1"
  4. The next receipt of a list of messages without parameters will display only the messages that were not received before this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question