Comments (11)
You usually can obtain access_hash
from the users
field of some updates.
import { ag, api } from 'airgram'
airgram.updates.use((ctx: ag.UpdateContext<any>, next) => {
if ('users' in ctx.update) {
ctx.update.users.forEach((user: api.UserUnion) => {
// save user.access_hash to somewhere
})
}
return next()
});
from airgram.
Ok. Got it.
I get full updates
event, that includes updateNewMessage
.
Full updates
event object:
{ _: 'updates',
updates:
[ { _: 'updateNewMessage',
message: [Object],
pts: 570,
pts_count: 1 } ],
users:
[ { _: 'user',
pFlags: {},
flags: 4194411,
id: 123456789,
access_hash: '999999...999',
first_name: '...',
username: '...',
photo: [Object],
status: [Object],
lang_code: 'ru' },
{ _: 'user',
pFlags: [Object],
flags: 17419,
self: true,
bot: true,
id: 999999999,
access_hash: '999999...999',
first_name: '...',
username: '...',
bot_info_version: 1 } ],
chats: [],
date: 1544620388,
seq: 0 }
from airgram.
@esindger If I do not want to use all updates
middleware, but only updateNewMessage
, in ctx.update
I get only "nested update":
{ _: 'updateNewMessage',
message: [Object],
pts: 570,
pts_count: 1 }
However full update event is:
{ _: 'updates',
updates:
[ { _: 'updateNewMessage',
message: [Object],
pts: 570,
pts_count: 1 } ],
users:
[ { _: 'user', ... },
{ _: 'user', ... } ], }
Is it possible to get access to "full" update event inside updateNewMessage
handler?
E.g. ctx.client.a.b.c.fullUpdateEvent
from airgram.
Nice to see fast support in this project! Thanks.
Actually, maybe I do not need "full" event object with users. What I need is "simple" reply() function.
Like in Telegraf reply().
reply (...args) {
this.assert(this.chat, 'reply')
return this.telegram.sendMessage(this.chat.id, ...args)
}
This function is used in a lot of examples:
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply('👍'))
The same I want to achieve with Airgram (however Airgram will be more powefull, so I can use it for bot and fo user). E.g. somewhere in updateNewMessage
handler:
type OnlyOneMessageUpdateContext = /* here I want context that will contain only one message at time, so airgram will easily detect to which message it must reply */ UpdateContext;
airgram.updates.on(`updateNewMessage`, (ctx: OnlyOneMessageUpdateContext) => {
if (update.message === '/start') {
await ctx.reply('Hello!');
await ctx.reply('Nice to meet you!'); // reply to the same message twice
}
});
- Airgram should detect to whom airgram must reply (whether message was sent from chat or directly from user). I see that using bot API is much simpler in this case, just to use sendMessage and send chat or user id. With MTProto (Airgram) this will be harder task.
Probably detect message type as
to_id: { _: 'peerChat', chat_id: ... } // then reply to chat
to_id: { _: 'peerUser', user_id: ... } // then reply to user
- Because of async handlers I should be confident that current context contains the same message (the same users array).
But anyway, if I will get access to users array in updateNewMessage
I will try to implement reply() function on my own.
from airgram.
Is it possible to get access to "full" update event inside updateNewMessage handler?
Since v0.1.9 you have access to the parent update by ctx.parent
property.
airgram.updates.on(`updateNewMessage`, (ctx: ag.UpdateContext) => {
console.log(ctx.parent)
});
from airgram.
For now, there is no plan to implement reply()
function but we can refactor code to put creating of context into separate method createContext
. Then you will be able to inherit this method and extend context.
from airgram.
Since v0.1.9 you have access to the parent update by ctx.parent property.
Awesome! Thanks!
For now, there is no plan to implement reply() function but we can refactor code to put creating of context into separate method createContext. Then you will be able to inherit this method and extend context.
Got it. If you will make it - it would be nice.
from airgram.
airgram.updates.on(`updateNewMessage`, (ctx: ag.UpdateContext) => {
console.log(ctx.parent)
});
In typescript I get compile error:
[ts] Property 'parent' does not exist on type 'UpdateContext<UpdatesResponse>'. [2339]
Am I missing something?
from airgram.
In typescript I get compile error:
[ts] Property 'parent' does not exist on type 'UpdateContext'. [2339]
Am I missing something?
Please check out package.lock
which version is installed. This will work start from version 0.1.9
.
from airgram.
Now you can extend updates context. Please check out the example
from airgram.
Please check out package.lock which version is installed. This will work start from version 0.1.9.
Yep. With version 0.1.9
removed package-lock.json
and run npm i
- helped. Thanks!
Now you can extend updates context. Please check out the example
Awesome! Thanks!
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.