Closed Asjas closed 3 years ago
where are you getting these telegramIds from? you also need to know the access hash of a user to use it in any API call.
The telegram ID is coming from the bot ctx.
When the user clicks on the keyboard button I listen for it using the bot, I then get the user id from the ctx and I call that function with the telegram id of the user.
This is what the code looks like that calls the function.
import type TelegrafPKG from "telegraf";
import type { Update } from "typegram";
import type MyContext from "../types/telegram";
import * as keyboards from "../messages/botKeyboards";
import { botReply } from "./reply";
import inviteUserToChannel from "../services/inviteUserToChannel";
export default function JoinChannelCommand(bot: TelegrafPKG.Telegraf<TelegrafPKG.Context<Update>>) {
bot.hears("Join Channel", async (ctx: MyContext) => {
try {
const { id: telegramId } = ctx.message.from;
await inviteUserToChannel(telegramId);
await botReply(
ctx,
"Thank you, you've successfully joined the Telegram Channel.",
keyboards.fullBotKeyboard(ctx),
);
} catch (err) {
console.error(err);
}
});
}
did this ever work for you? The id on its own is somewhat useless for accounts. They also need to see the access hash of the user which is unique per account.
So you would need to forward a user's message to the user account so they can see the access hash then the library will save it in the store folder (it's a .accessHash field). If the user account has never seen the user's profile it can't do anything with it.
As for the warning it should be fixed in 1.8.1
This hasn't ever worked for me because this is the first time I'm trying this.
I am using the Telegram API (gramjs) to invite a user to a private channel when they click on a keyboard button of a telegram bot that we are using.
I am creating a session with my phone number and I'm saving it to disk. When I need to make the API call I restore the session from disk.
I'm getting a
wrong type for accessHash
error message, do you know if this is an issue or something that I should ignore?I've gotten these random
accessHash
error a few times before and I don't know if it's random and whether I should ignore it or whether it shows a bigger problem that I need to fix. 🙂This is the error message.
This is my code for the
InviteToChannel
API call. I am using thetelegram id
of a user since not all users will have usernames configured.Am I perhaps using the wrong API function to get the User? Looking at the TypeScript in my code editor and it shows that
users
should be passed an array ofEntityLike
.This is the code I'm using to generate and save the session to disk (if that matters).