Closed alexpts closed 3 years ago
same question
up
Why are you passing the user's access_hash? I think you need to use the access_hash of the channel
@alik0211 Where I can find access_hash
of the channel via bot account?
Please use this method "messages.getAllChats" or corresponding bot method. messages.getAllChats From there you will get all the access_hash corresponding to each channels, you can save and reuse when needed.
@alik0211 Where I can find
access_hash
of the channel via bot account?
@atiquefiroz, @alik0211 My code:
try {
result = await mtproto.call('messages.getAllChats', {
except_ids: []
});
} catch (error) {
console.error(error);
return;
}
I have error on method messages.getAll.Chats
{
"_": "mt_rpc_error",
"error_code": 400,
"error_message": "BOT_METHOD_INVALID"
}
This method not available for bot
@atiquefiroz, @alik0211 My code:
try { result = await mtproto.call('messages.getAllChats', { except_ids: [] }); } catch (error) { console.error(error); return; }
I have error on method
messages.getAll.Chats
{ "_": "mt_rpc_error", "error_code": 400, "error_message": "BOT_METHOD_INVALID" }
This method not available for bot
I dont see any methods on telegram official website, i guess you will have to use update hook to read incoming chat, and you can reply on that through bot.
@atiquefiroz Bot API don`t have access_hash
on incoming webhook message - https://core.telegram.org/bots/api#chat.
I want get all members in group/supergroup.
Similar case -> https://docs.madelineproto.xyz/getPwrChat.html. I have supergroup scalar id only for fetch all members (https://docs.madelineproto.xyz/API_docs/types/InputChannel.html).
I get access_hash via https://docs.madelineproto.xyz/getPwrChat.html. But it not work too:
Full code without real secret:
const {MTProto} = require('@mtproto/core');
const {tempLocalStorage} = require('@mtproto/core/src/storage/temp');
const api_id = 11111;
const api_hash = 'xxxxx';
const mtproto = new MTProto({
api_id,
api_hash,
customLocalStorage: tempLocalStorage,
});
mtproto.updateInitConnectionParams({
app_version: '10.0.0',
});
// 3. Get the user country code
(async () => {
let user = await mtproto.call('auth.importBotAuthorization', {
bot_auth_token: "1111111:xxxxxxxxxx"
});
try {
let result = await mtproto.call('channels.getFullChannel', {
channel: {
_: "inputChannel",
channel_id: -1001421468496,
access_hash: 2400495907992991377 // get via madelineproto for chat -1001421468496
}
});
} catch (error) {
console.error(error);
return;
}
})();
I have error:
{
"_": "mt_rpc_error",
"error_code": 400,
"error_message": "CHANNEL_INVALID"
}
Any ideas how debug it?
@alexpts try use contacts.resolveUsername
for get information about the channel
Example - https://mtproto-core.js.org/docs/call-the-telegram-methods#parse-all-messages-from-channel
I can't get the list of users in supergroup through the bot account on version 6.0.1.
let peer = await api.call('contacts.resolveUsername', {
username: 'my_some_bot',
});
I added my bot to group and to supergoup.
Peer have not any group/supergoup. Property peer.chats
is empty array.
I see implementation of MadelineProto.
Method https://docs.madelineproto.xyz/getPwrChat.html can return full info by channel_id
only.
In code MadelineProto send access_hash = 0
- https://github.com/danog/MadelineProto/blob/8b15b79d8312aa6456e69417450e647b7d7fc1ef/src/danog/MadelineProto/MTProtoTools/PeerHandler.php#L587 and it work
@alexpts
I can't get the list of users in supergroup through the bot account on version 6.0.1.
let peer = await api.call('contacts.resolveUsername', { username: 'my_some_bot', });
I added my bot to group and to supergoup. Peer have not any group/supergoup. Property
peer.chats
is empty array.
you should resolve username of group chat not the bot username. and about madeline proto it is a heavy and buggy library please don't expect this project to be of same kind.
Group is private and have not username
your bot is already a member of the group?
if its already member of group/channel use updates handler to get access_hash https://mtproto-core.js.org/docs/setup-handle-updates
if its already member of group/channel use updates handler to get access_hash https://mtproto-core.js.org/docs/setup-handle-updates
@IRGC, it is webhooks for bot? I will try it.
I found problem with error CHANNEL_INVALID
. Channel_id
is not equal chat.id
from webhook bot api. (https://github.com/danog/MadelineProto/blob/8b15b79d8312aa6456e69417450e647b7d7fc1ef/src/danog/MadelineProto/MTProtoTools/PeerHandler.php#L63)
I will post full work code here.
if its already member of group/channel use updates handler to get access_hash https://mtproto-core.js.org/docs/setup-handle-updates
@IRGC, it is webhooks for bot? I will try it.
No. its for getting updates using this library similar to what we receive in webhook.
I found problem with error
CHANNEL_INVALID
.Channel_id
is not equalchat.id
from webhook bot api. (https://github.com/danog/MadelineProto/blob/8b15b79d8312aa6456e69417450e647b7d7fc1ef/src/danog/MadelineProto/MTProtoTools/PeerHandler.php#L63)I will post full work code here.
for channel_id remove prefix -100 from chat.id received in webhook.
No. its for getting updates using this library similar to what we receive in webhook.
What native methods it use? Where I can read more details about?
for channel_id remove prefix -100 from chat.id received in webhook. Thanks. It more simple that in
MadelineProto
. MadelineProto code is:
let newId = -id - Math.pow(Math.floor(Math.log10(-id)));
I have error:
How I cant get all users ids from supergroup via MTproto an bot token?