Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Persist bot's and user's state and ability to create conversations

Open dvygolov opened this issue 2 years ago • 5 comments

Beautiful library python-telegram-bot has some killer features I'd love to see in this .NET package:

  • bot_data: a dictionary, that can be used to store some data assosiated with the bot itself. It is available in every update request.
  • user_data: a dictionary that is user specific. When we get updates from the user, we can always take a look at user's data and change smth there or get additional info from there
  • conversations: this is so-so-so cool! You can define a conversation which is just a set of triggers and handlers. One can lead to another and it is very easy to create various flows of interaction with the bot. Here is an example: https://docs.python-telegram-bot.org/en/v20.0a6/examples.persistentconversationbot.html

dvygolov avatar Dec 09 '22 09:12 dvygolov

Hi,

I've create a small library that achieves exactly this. It is not public, because it is not separated from my business logic, but I could think about releasing it to the public if needed. It uses the Dipendency Injection pattern and it is really easy to use :)

lorenzo93 avatar Mar 22 '23 17:03 lorenzo93

https://github.com/TgBotFramework

It gives you all of the above, except for conversations, but you can easily implement them. Plus you can store them in DB with some amount of EF code to support it )

Any way data that you need to store is unique to your bot, so its hard to find solution that fits everyone

Fedorus avatar Mar 22 '23 23:03 Fedorus

Any way data that you need to store is unique to your bot, so its hard to find solution that fits everyone

A simple Dictionary<string,object> will fit everyone 🙃

dvygolov avatar Mar 23 '23 10:03 dvygolov

A simple Dictionary<string,object> will fit everyone 🙃

Dictionary<long, Dictionary<string,object>> 🙃

Fedorus avatar Mar 23 '23 10:03 Fedorus

You need to use Generics and do a Dictionary<long,T> so each developer could choose its own implementation. Moreover you should automatically find the scope dedicated to the user and give back the result.

lorenzo93 avatar Mar 23 '23 11:03 lorenzo93

For now we are making the choice that Telegram.Bot is the basis library for building bots and more high-level bot frameworks.

It is up to these framework to keep context & state for following users conversation.

See issue #1072 for a list of such frameworks available.

wiz0u avatar Jul 10 '24 13:07 wiz0u