How to retrieve username from the chat_id? - python-telegram-bot

I'm in the process of learning how to create a telegram bot and I seem to have run into an issue haha.
I currently store the chat_ids of all the users who chat with the bot, into an SQLite database. This is to allow the bot to be able send them a message at a later time, via their respective chat_ids. However, I would also like to retrieve their telegram username, to use it as part of the message that the bot will be sending.
I know I could simply store the usernames as well when they initiate a chat with the bot, however this is probably not a good solution as users may change their username, making the usernames in the database no longer correct.
May I know if there is a way within python to retrieve the user's telegram username using their chat_ids?
Thanks!!

If you are using python-telegram-bot, you can use bot.get_chat(chat_id) to get info such as first_name, last_name, username
For more info on that, visit the docs

Assuming that you're using python-telegram-bot, here's how you can retrieve currents first , last and user names:
first_name = update.message.chat.first_name
last_name = update.message.chat.last_name
user = update.message.from_user

Related

Read emails from multiple account, is that possible?

I created a new gmail project using my own google account. after creating the credential, I could use the following code to fetch my own emails.
result = service.users().messages().list(userId='me').execute()
My question is what should I do if I need to fetch emails from other accounts, such as 20 different accounts? list all of their userIds in the list function?
Thanks
When you ran your code the first time it asked you to authncate yourself, login to google and consent to the application accessing your email.
You will need to do this for each of the twenty users. Each user must grant your application access to their data only then can you access it. then for each user you can do
result = service.users().messages().list(userId='me').execute()

Okta - Bulk Import New Users With Default Password Via CVS

Is there a way to bulk import new users into Okta and have all their passwords be default set. Example upload 50 users with first name, last name, email, salesforce id, and a default password of 123QWEasd!
I read this https://help.okta.com/en/prod/Content/Topics/users-groups-profiles/usgp-import-users-csv.htm, but I don't think you can set the password.
You likely want to look into scripting this and just using the Users API endpoint to loop through your list of users and create the user with the default password. ]
You can also check out the Okta Management SDKs to help format the API call if you expect that you will need to do this again, otherwise a simple script or even something like the Postman Runner tool should suffice

Is there a way my rasa chatbot can know the logged in user full name and greet him?

I'm currently working on Rasa framework to develop a chatbot. I want to know how do i greet the user with his/her own name. For instance, the user will login to the application and then when he clicks on the chatbot icon it should know who logged in and greet the user. Is there a way i can achieve this.?
I've successfully worked with HTTP API calls as well. So fetching data from Database isn't hard. My assumption on how to achieve this is through session data. I believe there has to be something in the session data where i can get the username.
When a user clicks on the chatbot icon, you will send a query to the rasa framework. You can add the name of the user to the query, and in the action server of rasa, use the name for greeting the user.

Best practice to create a user in table and invite them to login

I am working on a Laravel project. I need to be able to create a user, mark that user with a number for their 'plan_id', and then invite them to log in and change their password. Currently, I am creating a user, adding the 'plan_id', and setting the password to a generic term like 'password'. I don't have info like their SSN or DOB that I could set it to initially.
While this does work, I don't know that it follows best practices. The only other thing I can think of is setting up another table that matches up the user's email address to the 'plan_id'. I don't want to do this because it makes it possible that the user accidentally signs up with another email and can't figure out why their portal is not working.
It doesn't sound like a great idea to set all new passwords to "password". It looks like your application is creating users, then letting each user know they have an account, as opposed to the user initiating this process. This would mean that you can't have the user pick a password.
Consider not creating a password at all, but sending an email to each new user containing a link to your system with a unique key that you store in the database user record. The user could then access the system, and it would ask them to pick an email and password to be registered with. You could have the keys expire after a number of days.
The easiest way to do this would be to generate a completely random password for the user and then email them a password reset link. The potential pitfall of this is that password reset links expire, by default after 1 hour though you can change it in config/auth.php.

oracle apex email and sms authentication

I want to Create a user screen with Two authentications (SMS and Email)
User will receive email to verify and activate his account first.
After that he set password and he will receive SMS massage to verify the password.I want to do this in Oracle apex.I have tried Custom Authentication but i didn't found fruitful, Any one have some good idea to achieve this.
after u take care of the email and sms verification, u should store that data in the data base and create a function to use in your custom authentication that verifies if the user is already validated.
put the function in shared components -> authentication schemes -> settings -> Authentication Function Name
(the function must return true or false to allow the login)
I'm not a fan of using SMS for Two-Factor Authentication, but if you must, perhaps this might demo implementation for Time-based One Time Password (TOTP) might give you some ideas: https://github.com/fuzziebrain/orclapex-tfa-demo
I provided some background information here as well: https://fuzziebrain.com/content/id/1718/
Good luck!
I have achieved this in one of my APEX project but only with the e-mail. For the sms I use it in another context but you could still do it. You will need a smtp server ( you can run one on your server ) and for the sms you will need an external provider. In your oracle database, create a table called OTP ( one time password ).
This table contains a foreign key to a user. When the user creates an account, run a dynamic action in pl/sql that will generate a random 6 digit number that will be encrypt in your OTP table. This dynamic action will also send an email to the user with APEX_MAIL. The full documentation for how to use APEX-MAIL is here and it is pretty easy to use. You can send the user the password for authentication trough email.
Create a new session user called user_na (not authenticated) and make it so that when he connects, the only page he can see is a page with a text field to enter the password he receive through email. After he enters it, encrypt it the same way you did when he created an account and compare the password in the OTP table. If they match , change his account type to user and then he will be able to access every page that you made accessible for the users.
If you also want to send an sms, I recommend using this tutorial. The sms provider have a free trial if you want to test. If you have any questions don’t hesitate to ask I can easily help you with this.
NOTE: if you don’t want to create different session_users you can just add a column in your user table named authenticated. Set it to 0 by default and to 1 when he enters the email password. Then, when he log in, check if this value is 0 or 1 to know which page you should redirect him to.

Resources