I'm using a telegram bot to maintain a private group, where I kick the user accordingly.
It works great but then comes this issue, When I use bot.ban_chat_member(user_id, chat_id) or bot.kick_chat_member(user_id, chat_id) to remove a user from the chat I can't add the user back again.
After I use bot.unban_chat_member(chat_id, user_id) and send an invite link to the user that I kicked, The user can't join the group. It shows that the channel is private and the user should wait for admin approval.
The only way allowed to join the group is by using an invite link generated by the bot.
What is the issue? How can I fix it? I can't afford anything else except the invite link generated by the bot.
Related
I've been using a Telegram BOT to send notifications for a group, and for users.
I already know i can get Chat ID by receiving a message from the user on my bot, using getUpdates.
I also know i can get Group ID using the same method...
But what i really need is:
There is three users in my group.
My bot.
Me.
Another user that didn't sent any messages to my bot so it does not appear on getUpdates
Is it possible to get this third user his ID?
PS: I am the group owner, and also added my bot as Admin...
The third user is a normal user.
Can someone help me?
Thanks!
That's not possible with the offical Telegram Bot API
Possible Workarounds:
Hold a list of your own. If a user is joining (new_chat_member), lefting (left_chat_member), somebody is sending a message in the group, and so on. Check Message for more information.
Check if a user is a member of the group with getChatMember.
Also may be helpful: getChatMembersCount and getChatAdministrators
I know that a telegram bot can't start conversation with the user. So user should click "/start" first. But for how long bot can respond to the user after the last message? Do any limitations exist like 24/48 hours?
Do any limitations exist like 24/48 hours?
No. After a user starts a conversation with a bot, the bot can send messages to that user until one of the following actions occur:
User 'Stop and blocks' the bot (See picture below)
User account gets deleted
For example, using the Desktop version, the user can 'Stop and block' a bot by pressing the following button:
I'm on a telegram group of wich I'm not admin. In that particular channel, there are lots of messages and "useless" information. I want to make something so when someone in the group says a particular word, I'll get a notification (maybe a private msg?). I've searched but other answers mention the bot API, but, as far as I have found, bots can't be added to groups without being admin, not even with the invitation link. How can I access the messages of the group to process them?
As you said, bots can't get message in channel without administrator permission, and they can't join group by themselves.
If you want to get all messages in group, please disable privacy mode via /setprivacy in #BotFather, and re-invite to group.
Is it possible to create a bot who manage more than one conversation with one user?
I need to create a bot able to make the link between a random chat and telegram.
For example, if I don't wont to use Facebook Messenger anymore, creating a bot who send me every new Facebook message from my account to my Telegram number. The bot would create a new conversation for each unique Facebook user sending me message. Or, if it's not possible, a bot who create a new temporary bot for each new user conversation and give me his #name.
Is it possible with the Telegram Bot API?
According to the latest telegram bot api you can make more than one bot, but one thing that is crucial is the bot's API token that is made manually through botFather. You can make a single bot and make other bots inherit its features and every time a new user sends you a message assign a bot to him/her. Up to here, it's possible but for API token all you can do is to make as much bots as your Facebook friends count and store their api tokens in a DB and pass one of the api tokens to the bot that stands for a user.
This is what I think can solve your problem but the api token part is a bit strange 😀 although you can send a notification from the main bot to your own account when the number of unsigned api tokens get less than 5.
As you know the number of Facebook friends can change and any of them at any time can text you so there must be enough tokens because every time one of them texts you for the first time a bot must be created with a pre-made api token and inherit the features from the main bot. From that moment that token and that bot stand for the person who tried to message you.
Also I think there must be a limit to the number of the bots that you
can make using one telegram account which can be solved using
different accounts.
What you want is possible, as you know every single telegram user has a unique chatID in telegram so if your friends or users text to your bot directly you can use a code like below to answer their messages from your own telegram account and make the bot send it to the related user:
if(update.Message.Text != null)
{
var req = new SendMessage(Your_Own_ChatID, "This message is sent from the user with chat ID: "+update.Message.Chat.Id.ToString()+"\n In order to reply it type the user's chat ID and add one comma then type in your text and tap on send.\nThe message:"+ update.Message.Text);
await bot.MakeRequestAsync(req);
continue;
}
else if (update.Message.Text.Contains(",") && update.Message.Chat.Id == Your_Own_ChatID)
{
string sender_chatID = update.Message.Text.Split(',').First();
string Message = update.Message.Text.Split(',').Last();
var req = new SendMessage(long.Parse(sender_chatID), Message);
await bot.MakeRequestAsync(req);
continue;
}
But if your users send the messages from Facebook to you and you want the bot to send them to your telegram account and answer them again through the bot using Facebook API or something else, all that must change is:
Instead of sender's Chat ID you must save his/her Facebook username and reply it with the FB username instead of telegram Chat ID.
Note that this code is just a sample and of course separating the Chat ID and the reply is a simple solution, but my recommendation is to use inline or custom keyboards to answer the message and that way you don't even need to type down the user's ChatID or FB account.
Also you can use telegram's reply feature and check if the reply is null and find the Chat ID(or FB account or ...) of the sender of the message your trying to reply and send the reply directly to that user.
That is achievable using the method that is used in this project.
[https://github.com/idoco/intergram][1]
Essentially, you create a random userid for each user. In order to reply to that specific user, you have to use the reply to message method in your telegram client. Ie... right click on the message to reply to it.
I need to create a Telegram bot to moderate a group and be able to ban/boot/kick users from the group.
I could not find anything in the Telegram API to boot a user from a group, how can a bot do this through the API?
You can use banChatMember to remove a user from a group.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
To remove a user without banning them, use unbanChatMember.
this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat.