mtproto-core
mtproto-core copied to clipboard
Filtering message and channel
Hi, I don't find in the documentation information on the way to decode message received in the event 'updates'
mtproto.updates.on('updates', (updateInfo) => {
console.log('updates:', updateInfo);
});
The updateInfo looks like :
{
_: 'updates',
updates: [
{
_: 'updateReadChannelInbox',
flags: 0,
channel_id: 1111111111,
max_id: 110,
still_unread_count: 0,
pts: 111
},
{
_: 'updateNewChannelMessage',
message: [Object],
pts: 111,
pts_count: 1
},
{ _: 'updateDraftMessage', peer: [Object], draft: [Object] }
],
users: [
{
_: 'user',
flags: 1111111,
self: false,
contact: false,
mutual_contact: false,
deleted: false,
bot: true,
bot_chat_history: false,
bot_nochats: false,
verified: false,
restricted: false,
min: false,
bot_inline_geo: false,
support: false,
scam: false,
apply_min_photo: true,
id: 11111111,
access_hash: '11111111111111111111',
first_name: 'Channel',
username: 'Channel_Bot',
photo: [Object],
bot_info_version: 4
}
],
chats: [
{
_: 'channel',
flags: 111111,
creator: true,
left: false,
broadcast: true,
verified: false,
megagroup: false,
restricted: false,
signatures: false,
min: false,
scam: false,
has_link: false,
has_geo: false,
slowmode_enabled: false,
call_active: false,
id: 111111111,
access_hash: '11111111111111',
title: 'TestChannel',
photo: [Object],
date: 1621968037,
version: 0,
admin_rights: [Object]
}
],
date: 1623271207,
seq: 111
}
I've found the channel ID in chats=>title The message is in update message I suppose.
How can I extract the Title and the message .
Thanks
mtproto.updates.on("updates", ({ updates }) => { const newChannelMessages = updates .filter((update) => update._ === "updateNewChannelMessage") .map(({ message }) => message); });