Comments (7)
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.
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.
If bot considered as a
InputPeerUser
how do I getaccess_hash
for it?
Access hash can be obtained from updates or from results of the messages.getDialogs
method.
from airgram.
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.
$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.
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.
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)
- error {code = 400 message = "Failed to parse JSON object as TDLib request: Can't parse "<bot_id_string>" as an integer"}
- failed authentication telegram when using self signed certificate
- check sending status
- how to import telegram web UI
- how to import telegram web UI
- Valid api_id must be provided. Can be obtained at HOT 10
- Chat info not found
- API object show empty {} and not working any api function
- Airgram JavaScript example not working HOT 1
- TdLib 1.8.6+ requires modified authorization object. HOT 1
- Example/how-to on how to access database (messages)?
- Reactions missing from MessageInteractionInfo
- is posible, create and manage bots with airgram?
- Enable `ignore_background_updates` in Airgram HOT 1
- spoilered message is unsupported
- "@airgram/web": "^5.0.0", cannot send images when running on the browser. No matter what value the Path is set to, it will display [sendMessage][400] Can't find real file path.
- Incompatible architecture [macOS]
- Auth Problem: Cant receive code
- Execute bot command in 1-1 personal chat instead of showing command text
- Is this project maintained? the current version is not compatible with the latest version of TDLib
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from airgram.