Answer the question
In order to leave comments, you need to log in
How to run a bot via telegram api?
I automate human actions in the telegram client. The task is this: create a group with a list of contacts, add a bot to it and run it. Everything worked out except for the last points (well, still make the bot an admin, but this is impossible without adding the bot to the group, and this does not work :) ) I use https://github.com/zerobias/telegram-mtproto
as a library that provides API
bot = {user_id: 120593101, access_hash: ''}; // это бот chgk_bot, но и с другими не работает
peerSelf = new telegram.schema.type.InputPeerSelf();
userBot = new telegram.schema.type.InputUser({props: bot});
return client.callApi('messages.startBot', {bot: userBot, peer: peerSelf, random_id:123456, start_param:'start'});
return client.callApi('messages.addChatUser', {chat_id: chat, user_id: userBot, fwd_limit:1});
Answer the question
In order to leave comments, you need to log in
The point is that your access_hash is empty. Try contacts.resolveUsername method
const { InputUser, InputPeerSelf } = telegram.schema.type
const peerSelf = new InputPeerSelf()
const user = client.callApi('contacts.resolveUsername', { username: 'chgk_bot' })
const startBot = user.then(({ users, peer }) => {
const access_hash = users.list[0].access_hash
const user_id = peer.user_id
const userBot = new InputUser({ props: { user_id, access_hash } })
return client.callApi('messages.startBot', {bot: userBot, peer: peerSelf, random_id:123456, start_param:'start'})
})
startBot.then(result => console.log(result))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question