0
votes

I want my BOT to ask the user a question.

Let's say I have an empty string named "email"

And I set email=''

Let the question be the user's email. So the bot will ask the user to type his email, then whatever the user types next after the question, the bot will save that reply and update the email.

I already know that by default any reply/message sent to a telegram bot is stored and you can retrieve it by using the getUpdates method.

Let's say the user replied: "name@Gmailcom"

So now I want to store this reply in the variable 'email'

So the variable 'email' will now contain the value '[email protected]'

I want the bot to contain an account section. So when the user clicks this button it will diplay something like this:

User: 

Email:

No of Referrals:

So when the user clicks on the button "ACCOUNT" it will display:

User: JOHN

Email:

No of Referrals:

#Since email='' therefore email is blank.

Now when the user updates his email and then goes back and clicks "Account" we now have:

User: JOHN

Email: [email protected]

No of Referrals:

Also please is it possible immediately after the user updates his email and sends the reply, then the BOT will reply with a message like:

Thank you for updating your Email address 

Your email is : [email protected]

Also if you have idea on how to create referral link using telegram bot, please share it.

How can I do this. I'm using pyTelegramBotAPI.

1

1 Answers

1
votes

Easy answer:

You need a data base

E.g. I have developed a budgeting telegram bot that stores daily purchases and analyses spending.

I store all user data in a separate data base (in this case redis) and access it later.

Given your use case I would recommend a simple key-based data base like redis where you can store and access simple dict-like data. Heroku and other web services that are popular for hosting telegram bots also do offer free redis instances.

Here is a sample code from my bot

# Load/create pickle and add new record, afterwards save pickle
    try:
        user_id = str(update.effective_user.id)
        db = pickle.loads(r.get(user_id))
        db.append(entry)
        pdb = pickle.dumps(db)
        r.set(user_id,pdb)
    except:
        user_id = str(update.effective_user.id)
        db = list()
        db.append(entry)
        pdb = pickle.dumps(db)
        r.set(user_id,pdb)

    update.message.reply_text('Saved!')