Giter VIP home page Giter VIP logo

Comments (7)

volodalexey avatar volodalexey commented on July 21, 2024 1

I found how it works in Telegram web application - webogram.
As a user you go to search tab. When you type something, app sends two search requests client.contacts.search and client.messages.searchGlobal.
I reproduced the same with airgram

airgram.client.contacts.search({
      limit: 1,
      q: '@SuperBot',
    })
airgram.client.messages.searchGlobal({
      limit: 1,
      q: '@SuperBot',
      offset_date: 0,
      offset_id: 0,
      offset_peer: { _: 'inputPeerEmpty' }
    })

The first one client.contacts.search request works for me (both in airgram and in webogram). As a result I get:

{ _: 'contacts.found',
  results: [ { _: 'peerUser', user_id: 677359809 } ],
  chats: [],
  users: 
   [ { _: 'user',
       pFlags: [Object],
       flags: 16395,
       bot: true,
       id: 123456789,
       access_hash: '1111111111111111111',
       first_name: '...SuperBot...',
       username: '...SuperBot...',
       bot_info_version: 2 } ] }

Altogether:

const { users } = await airgram.client.contacts.search({
    limit: 1,
    q: '@SuperBot',
  });
  if (users.length) {
    for (const user of users) {
      if (user._ === 'user') { // check user id probably?
        await airgram.client.messages.sendMessage({
          message: `/start`,
          peer: {
            _: 'inputPeerUser',
            user_id: user.id,
            access_hash: String(user.access_hash),
          },
          random_id: String(Date.now())
        })
      }
    }
  }

from airgram.

 avatar commented on July 21, 2024

Telegram bot represents as a user, not as a chat. Something like this:

{
       _: 'user',
       flags: 49163,
       bot: true,
       bot_chat_history: true,
       id: XXX,
       access_hash: 'XXX',
       first_name: 'Super Bot',
       username: 'SuperBot',
       bot_info_version: 1 
}

from airgram.

 avatar commented on July 21, 2024

If bot considered as a InputPeerUser how do I get access_hash for it?

Access hash can be obtained from updates or from results of the messages.getDialogs method.

from airgram.

volodalexey avatar volodalexey commented on July 21, 2024

Ok. Thanks.
If user does not have the bot in his contacts jet - user must obtain access_hash by search?
How it is possible in other libraries to send messages without access_hash (not from updates event)?
E.g. MTProto implementation in Golang:

$ telegram msg 104842610 'Hack the planet!'

E.g. PHP MTProto - MadelineProto:

$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);

from airgram.

 avatar commented on July 21, 2024
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for > creating MadelineProto! <3"]);

MadelineProto internally resolves @danogentili to a valid peer value. If user does not found in local database, the library throws an exception.

from airgram.

 avatar commented on July 21, 2024

If user does not have the bot in his contacts jet - user must obtain access_hash by search?

Try the contacts.resolveUsername method:

const { peer } = await airgram.client.contacts.resolveUsername({
  username: '@SuperBot'
})

from airgram.

volodalexey avatar volodalexey commented on July 21, 2024

Ok. Thanks. This works (however without @):

const { peer } = await airgram.client.contacts.resolveUsername({
  username: 'SuperBot'
})

And as a result I get { _: 'peerUser', user_id: 123456789 } for bot, but I still need access_hash for this bot...

from airgram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.