Add user to channel automatically when user asks

给你一囗甜甜゛ 提交于 2019-12-21 22:10:26

问题


I want to make a very simple project that does this:

An user (let's call him John) opens a Telegram chat with my bot, and inputs this:

User John: /join channel1

My bot responds adding user 'John' to Channel 'channel1'

That's actually all I want. The problem is that Telegram BOT API does not implement any method to add users to groups. I tried to use telegram-cli but 'chat_add_user' only seems to accept adding user to chats, not to groups.

Is there any way I can add an user to a channel like that? (Without manually doing it) or should I forget about this?

Thank you!


回答1:


The bot ability is limited. It can only send and receive messages in a chat conversation and collect some information about other chat participants. It can not start a new conversation or other client functionality.

For automate your task, you should use telegram API. There are some clients such as telegram-cli that use the telegram api and have high level methods.

Other clients:

  • tgl (C)
  • kotlogram (Java)
  • telethon (Python)
  • webogram (Web)
  • MadelineProto (PHP)
  • TLSharp (C#)
  • pytg (Python wrapper for telegram-cli)



回答2:


You Invite other uses to your channel using:

channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector<InputUser> = Updates;

You can invite several uses at a time, via a list (Vector) of InputUser.

This seems consistent with Telegram Desktop and the mobile clients, which allows you to select multiple contacts and add them to your group.

InputUser is of the form:

inputUser#d8292816 user_id:int access_hash:long = InputUser;


来源:https://stackoverflow.com/questions/42448635/add-user-to-channel-automatically-when-user-asks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!