How get telegram user info by UserID? - python-telegram-bot

I have a user_id like 2024211111. How i can get user info by this user_id?
Tdlib api have a method called getUser, but it doesn't work with this user_id (this user_id not in my ChatList)

Simple answer: This function doesn't exist. You just can know User Info through a chat previously initiated. So, you have to start a chat with this user first to call the API method mentioned. If you need to query the info later, you should store it, there is no another way that I know

Related

Is there any way that hasura decodes the token and can use its content in a query?

I was wondering if there is any way to do this in hasura without resorting to creating another service.
Let me explain, in an api a user sends his token, this is decoded in the backend and and so we know who the user is, this is useful for example to search and return records in the database that only belong to this user.
Is there any way to do that with Hasura? the only return the records that belong to a certain user using its token?.
Token data is available as session data so you can use hasura column presets to insert the user id and add permission to only fetch rows that have user id equal to user id from session https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/default-values/column-presets.html#column-presets

How to store sessions of a telegram bot user in my db

I wanna code a telegram bot, so when I gonna receive messages from a user I should know about last message he/she sent to me and in which step does he/she located. So I should store sessions of the user (I understood this when I searched) but I don't know what exactly should I do?
I know I need a table in a db that stores UserId, ChatId but I don't know these:
How to make a root for steps and store them in db (I mean how do I understand where the user is located now)
What are other columns that I need to store as a session?
How many messages should I store in the database? And do I need one row for each message?
If you just have to store session in your database you don't need to store messages. Maybe you could want to store also messages but it's not necessarily related.
Let's assume you have a "preferences" menu in your bot where the user can write his input. You ask for the name, age, gender etc.
How do your know when the user writes the input of it's about the name or the gender etc?
You save sessions in your db. When the bot receives the message you check in what session the user is in to run the right function.
An easy solution could be a sql database.
The primary key column is the telegram user ID ( you additionally can add a chat id column if it's intended to work both in private and group chats) and a "session" column TEXT where you log user steps. The session column can be NULL by default. If the bot expects the gender (because the user issued /gender command) you can update the column "session" with the word "gender" so when the message arrives you know how to handle it checking the gender column of that user id and as soon as you runned the right function, you update to NULL again the column "session".
you can create a db with these columns.
UserID, ChatID, State, Name, Age, Gender ...
on each incoming update you will check if user exists on you db then check the user's State and respond appropriately and update the state at the end.

Group ID for "All Company" Group in Yammer

I'm using the Yammer REST API to fetch data about messages posted in our Yammer network.
I can get messages from any group by passing the group ID.
But I don't know the group ID for the All Company group.
How can I find the group ID for the All Company group?
Use https://www.yammer.com/api/v1/messages/general.json.
You can see the other built-in feed type endpoints such as my_feed and private here: http://developer.yammer.com/restapi/#rest-messages
Yammer API POST call with parameter group_id allows posting message to a group, but not to AllCompany.
Same POST call with parameter feed_id allows posting message to a group and to AllCompany group (feed).
Use feed_id instead of group_id and all as id.
first get all the groups
using this API
https://www.yammer.com/api/v1/groups.json
in that group array check out the group full name. and you can use id of that array item. that will be your group id.
Use https://www.yammer.com/api/v1/messages.json.
This will give All public messages in the user’s (whose access token is being used to make the API call henceforth referred to as current user) Yammer network. Corresponds to “All” conversations in the Yammer web interface.
also refer answer from by #mleroy in earlier message.
use "all" as feed id for All company group.
I know this post is a bit old but it might help someone.
On every group page of Yammer, there is a section called Access Options on the right had side.
Click on the link "Embed this group in your side". It will give you JS code for the group which will include Feed ID as well.
Using this api you can able access all messages
https://www.yammer.com/api/v1/messages.json
from the response json you can see the group id of all message groups.You can notice that 'group_created_id' is null for all company group.
I dont think that group id for all company is 'All',because that parameter is an integer,So just pass null.
Its a bit weird, but I found out that the group_created_id field is null when the message belongs to "All Company"
So you can use messages.json as mentioned before to get all public messages,
or if you want to search for messages by groups, you can get a list of groups ids and use :
https://www.yammer.com/api/v1/messages/in_group/{group-id}.json
and after that use messages.json, and go over the messages and search for those who has the field group_created_id set as null
Hope it will help someone someday :P
I had a similar requirement of embedding Yammer All company feed for which I needed the Feed ID and this worked for me-
feedType: "general",
feedId: "all"
Hope this helps!

How to identify a new PFRelation on AfterSave using Parse

Is it possible to identify what has changed on a PFRelation column on the AfterSave method of a table? I want to identify an User who liked an Item. The Item table has a UserLikes PFRelation which has all users that liked that Item. I want to trigger execute a notification whenever a new User likes an Item, but only for that new User, not the ones that liked it previously.
I'm not sure if that is possible. However, I would instead create a cloud code function for the notification, and then trigger that in the afterSave block for the like. If the like was successfully saved, notify the owner of the liked item.
If that doesn't work with your current data model, take a look at how Parse solves liking in the Anypic tutorial app.

MVC3 User Authentication link

In my application I have an administrator who can create Tournament objects. When the object is created the service also creates a user (based on the tournament director's info which was entered at creation). The username for the user is the director's e-mail, the password is randomly generated and then mailed to the director.
When the director logs on with his e-mail address and password, I need to be able to link him to his own tournament, in order to only allow him to edit his own tournament's details. I have tried to find a way to store the TournamentId in the default ASP Net Users database, but was unsuccessful.
I had a look at this SO question which would certainly help me, but I can't figure out how it would apply to my problem. When the user logs on, I can't put the TournamentId in the userdata seeing as I don't know it.
Should I then do a lookup in the Tournament table to see which ID corresponds to the email address entered at login and store that in the userData? It seems quite unelegant this way.
I guess you should have a CreatedBy column in your Tournament table where you store the ID of the user who created the tournament. Then when the user logged in, get his id ( may be from session ,if you store it there), Do a select query where CreatedBy=loggedInUserId .That should do the trick.

Resources