S
S
santavits2020-05-03 19:18:12
PHP
santavits, 2020-05-03 19:18:12

How to get the number of the last post in a telegram channel?

Good evening.
Faced such a problem, how can I get the id of the last post in the telegram channel?

The api has a getUpdates method, but to get information with this method, you need to add your bot to the channel administrators with which the desired channel will be parsed.

Are there any other options? without adding a bot to administrators

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Neverov, 2020-05-03
@TTATPuOT

No. Bots cannot parse other people's channels. And the getUpdates method doesn't work the way you'd expect. It only returns NEW posts that seem to be unread by the bot, but not the ID of the last post in the channel.

B
BindOf, 2021-09-26
@BindOf

dim xmlhttp

set xmlhttp    = createobject("msxml2.xmlhttp")

function getlastpostnumber2(channel, num)
  on error resume next
  dim   chhref
  dim   pos
  dim   cyphers
  dim   pos1
  dim   symcnt
  dim   z
  dim   wi
  const sl = "/"
  cyphers            = "1234567890"
  pos                = 1
  getlastpostnumber2 = num
  with xmlhttp
    .open "get", "https://t.me/s/" & channel, false
    .send
    while pos > 0
      pos    = instr(pos, .responsetext, channel & sl)
      chhref = ""
      if pos > 0 then
        pos1   = pos + len(channel) + 1
        symcnt = pos1
        while instr(cyphers, mid(.responsetext, symcnt, 1)) > 0
          if err <> 0 then exit function
          chhref = chhref & mid(.responsetext, symcnt, 1)
          symcnt = symcnt + 1
        wend
      end if
      if pos > 0 then
        pos = pos + 1
        getlastpostnumber2 = chhref
      end if
    wend
end function

Call:
lastpostnumber = getlastpostnumber2("TG channel name", N)
Notes:
1. N can be equal to 0 in general, but this variable can be set to the number of the last known post if we want to periodically receive updates from the channel. If, for example, the Internet connection is lost at the time of the function's execution, it will return the value N.
2. The msxml2.domdocument object can also be used, but it's better not to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question