API Index

Subpackages

Submodules

tgram_dnd.app module

class tgram_dnd.app.App(bot: TgBot, flows: List[MessageFlow | CallbackFlow] = [], config: BotConfig = None, cache: BaseCache = None)[source]

Bases: object

The main class used to run your Flows

add_flows(flows: List[MessageFlow | CallbackFlow] | MessageFlow | CallbackFlow)[source]

add flows to current app

run() None[source]

run the bot

tgram_dnd.config module

class tgram_dnd.config.BotConfig(strings: Dict[str, Dict[TypeAliasForwardRef('tgram_dnd.enums.language_codes.LANGUAGE_CODES'), str]] = None, keyboards: Dict[str, Dict[TypeAliasForwardRef('tgram_dnd.enums.language_codes.LANGUAGE_CODES'), InlineKeyboardMarkup]] = None, default_lang: tgram_dnd.enums.language_codes.LANGUAGE_CODES = 'en', bot_commands: List[BotCommandInput] = None, config_file: str = None)[source]

Bases: object

Init BotConfig

# Importing data manually
config = BotConfig(
    strings={
        "start": ...
    },
    keyboards=...,
    commands=...
)

# importing from a file
config = BotConfig(config_file="data.json")
Parameters:
Returns:

None

configure(bot: TgBot) None[source]

used to apply the configurations

Parameters:

bot (tgram.client.TgBot)

Returns:

None

keyboard(key: str, force_language: tgram_dnd.enums.language_codes.LANGUAGE_CODES = None) Callable[source]

used to return a keyboard based on the user language

Parameters:
Returns:

a decorator to get the keyboard based on user language

Return type:

Decorator

load_file_data(file: str) None[source]

Loads data from ConfigFile

Parameters:

file (string) – file path

Returns:

None

load_strings() None[source]
string(key: str, force_language: tgram_dnd.enums.language_codes.LANGUAGE_CODES = None) Callable[source]

used to return a string based on the user language

Parameters:
Returns:

a decorator to get the string based on user language

Return type:

Decorator

tgram_dnd.errors module

exception tgram_dnd.errors.InvalidStrings(msg: str)[source]

Bases: Exception

raised when the given strings argument is invalid

exception tgram_dnd.errors.StopBlock[source]

Bases: Exception

used to stop the block Execution

exception tgram_dnd.errors.StopExecution[source]

Bases: Exception

used to stop action Execution

tgram_dnd.utils module

tgram_dnd.utils.get_target_function(obj: object, function_name: str) Callable | None[source]

used to get a specific function from obj by getting its attribuites

# example with first class method
obj = Message
target = "reply_text"
method = get_target_function(obj, target)

print(method)
# <function Message.reply_text at 0xSomeAddress>

# example with indented method
obj = Message
target = "user.mention"
method = get_target_function(obj, target)

print(method)
# <funtion Message.User.mention at 0xSomeAddress>
Parameters:
  • obj (object)

  • function_name (str) – the wanted method seperated by dots, eg: obj_property.method_x

Returns:

Callable

tgram_dnd.utils.render_vars(string: str, *data) Any[source]

used to render all jinja-style variables

Parameters:
  • string (str) – the target string

  • *data (dict) – the data to fill with

Returns

Any

async tgram_dnd.utils.run_function(func: Callable | Action, *args, **kwargs) Any[source]

Module contents