Telegram Bot: Can we identify if message is from group admin? - telegram-bot

I have added my bot to a group chat, now for few commands I need to give access only to the group admin, so is it possible to identify if the message sender is admin of the group?
I am using python-telegram-bot library

When you use getUpdates, you can see .message.chat.type is group or not.
And then use getChatMember, .result.status should be administrator or creator.

It is absolutely possible. You can use the getChatAdministrators API method (returns a list of ChatMember) to get a list of admins for a chat, or the getChatMember API method (returns a single ChatMember) to get the admin status of a single user.
An efficient method to solve this problem is described here: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#cached-telegram-group-administrator-check

No. You need to hardcode user id in your source and compare if user id in admin-ids array.

Related

I want to delete the files once the user left the conversation in the bot framework (.netcore)

Actually, I want to delete all the files for that particular user which logged in to my BOT and once the user left the conversation. I want them all to delete as I am storing them in my wwwroot and I don't want it to store and keep it there.
Any suggestions will be helpful. how I will be able to achieve this. I am new to this?
TIA
I suggest you could try to use the ActivityHandler's OnMembersRemovedAsync method. This method provide logic for when members other than the bot leave the conversation, such as your bot's good-bye logic.
I think you could add some logic to to get the user id and delete the user according to this user ID.
More details ,you could refer to this article. About how to use this activity handler, you could refer to this welcome bot sample.

Identifying the Telegram-Bot-Owner not possible?

I am currently implementing a telegram bot that needs to differentiate between the one that owns the bot - meaning the one who has been provided with the bots credentials - and all other users chatting with the bot.
I am using webhooks and from what I can see, there is no parameter provided in the message object, that I could use to identify this relationship. Parameter like surname, lastname are not sufficient as they are ambiguous and the #username is not provided at all.
One could use the chat-id, but I cannot see any API Call that would offer userData ..
Any ideas ?
BR Andre
Using python, save your (admin) chat.id to a config file, then compare it via chat.id from incoming message entity.

Telegram check if user is admin

I am using the telegram bot api to make a bot. I have some commands that can only be sent from admins. Like kick and ban commands. How do I check if the sender is an admin or not? I am using the python-telegram-bot api. I do not want everyone to be able to ban members.
You can use getChatMember method. See following instance:
I have found after searching a bit. The admin status is stored under Telegram.ChatMember.status. It is documented here. It is used by bot.get_chat_member(chat_id, user_id). And then getting status in it.
The other answers are correct, but require an additional call to the API. An efficient solution is to cache the list of admins.
A good solution for this is described here, copied below:
Cached Telegram group administrator check
If you want to limit certain bot functions to group administrators, you have to test if a user is an administrator in the group in question. This however requires an extra API request, which is why it can make sense to cache this information for a certain time, especially if your bot is very busy.
This snippet requires this timeout-based cache decorator. (gist mirror)
Save the decorator to a new file named mwt.py and add this line to your imports:
from mwt import MWT
Then, add the following decorated function to your script. You can change the timeout as required.
#MWT(timeout=60*60)
def get_admin_ids(bot, chat_id):
"""Returns a list of admin IDs for a given chat. Results are cached for 1 hour."""
return [admin.user.id for admin in bot.get_chat_administrators(chat_id)]
You can then use the function like this:
if update.message.from_user.id in get_admin_ids(bot, update.message.chat_id):
# admin only
Note: Private chats and groups with all_members_are_administrator flag, are not covered by this snippet. Make sure you handle them.

Okta Api User Directory

Using the okta API, we're trying to display a simple staff directory. Basically we want to list all active users in a particular group on a web page.
Seems like it should be super simple.
If I use the user endpoint, I can get all users and filter by status to be active, but I can't seem to filter by group.
If I use the group end point, I can get all users in a group, but I can't seem to filter by status.
How should I be going about this?
Edit: Added my api calls
method 1
$filters = 'status eq "ACTIVE"';
$c = curl_init("https://wvuf.okta.com/api/v1/users?filter=".urlencode($filters));
method 2
$c = curl_init("https://wvuf.okta.com/api/v1/groups/xxxxGROUPIDxxxx/users");
Unfortunately, this is not possible in the current version of the Okta API. As you've surmised, you can either GET all users with an ACTIVE status and then iterate through them to get the groups for each user or GET all users for a specific group and manually filter by status.
The latter method may be preferable because it will amount to fewer calls (assuming there are more users than groups).
The List Group members (/api/v1/groups/${groupId}/users) endpoint does not support the filter query param
https://developer.okta.com/docs/reference/api/groups/#group-member-operations
One suggestion is to do some client side filtering (eg using jq etc)
The ListGroupUsers method in the Groups API for Okta enumerates all users that are a member of a specified group.
Have a look at this tool I created for a project I am on, okta-admin, wraps up the Golang SDK for Okta in an easy to use CLI (which effectively invokes REST API requests...)
okta-admin groups listusers $groupId
I have added the ability to pass filter arguments supported by the API or endpoint as well as a jsonquery argument where you can perform searches or projections client side.

how to find logged-in users using sorcery?

Is there any way to find the currently logged-in users and delete the sessions of particular users using sorcery?
Thanks in advance.
From the documentation:
Below is a summary of the library methods. Most method names are self explaining and the rest are commented:
# activity logging
current_users
You can use current_users to iterate through all your users. To log them out have a look at reset_session.