How do I know if a telegram user joined my channel?

守給你的承諾、 提交于 2019-12-24 07:53:48

问题


I am writing a C# desktop app.in this app I write a telegram Id of a user and it says that user is member of the channel or not. my bot is admin of the channel.

I use telegram.bot v9 nugget and searched about this issue all day.

I tried using GetChatMembersCountAsync() in v13 and a lot of other methods but didn't work.

    static private Api bot = new Api("Token");
    long id;
    string channel="@ChannelName";

    public Main()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        id = long.Parse(textBox7.Text);
        if (IsMember(id,channel))
            MessageBox.Show("This user is member of channel");
        else
            MessageBox.Show("This user is not a member of channel");

    }

    private bool IsMember(long id,string channelName)
    {
        //??????????????
    }

Is there a method for a telegram bot access to list of members of a channel? what should I write in the IsMember() method?

Thank you very much


This problem solved by updating telegram.bot nugget to v10 and using GetChatMemberAsync method.

    private bool IsMember(long id,string channelName)  
    {  
        var t = bot.GetChatMemberAsync(channelName, id);
            if (t.Result.Status.ToString().Length > 25)
                return false;
            return true;
    }

thank you


回答1:


You can use getChatMember method to do that, see following example.




回答2:


Regarding to Telegram Bot API documentation currently there is no method available for bots to get a list of chat members (channel or group). Here is a small trick: You can check the updates (messages) came from Telegram to your webhook, if new_chat_members field has a value and the chat_id field indicates that it's from your channel, then you may save the information about the recent users who joined your channel.



来源:https://stackoverflow.com/questions/46542451/how-do-i-know-if-a-telegram-user-joined-my-channel

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