Skip to main content

A python module to auto build conversation for a Telegram bot

Project description

Setup

pip3 install telegram-autoconv

Requirements

  • Python 3.8

Import

from autoconv.state import State
from autoconv.conversation import Conversation
from autoconv.autoconv_handler import AutoConvHandler

Documentation

I know you want examples, in fact there is a beautiful folder with some examples.
But here, you can find a little documentation.

State

State(name,message,type=int,parse_mode=None,back=False)
  • name: State name (and key for data dictionary). {str}
  • message: message you want to print in that state. {str}
  • type: data type. {type}
  • parse_mode: Telegram message parse mode. {Telegram.parse_mode}
  • back: enable back button. {bool}
# callback handler
add_keyboard(keyboard,size=None,max_row=3)
  • keyboard: inline keyboard. Can be a dict (with custom value as key) or a list (default int value as key). {name list or value:name dict}
  • size: size for each row of the keyboard. {int tuple}
  • max_row: total values in a row, ignored if size is specified. {int}
# callback handler
add_dynamic_keyboard(function,max_row=3)
  • function: function must have two parameters (update and context). It can return a dict or a list for a keyboard. Called when its state is reached. {func}
  • max_row: total values in a row. {int}
# text handler
add_text(regex=None,error_message=None)
  • regex: regex for input text. {str}
  • error_message: error message when regex fails. {str}
# function to execute in this state
add_action(function)
  • function: function must have two parameters (update and context). It can return a str, repleacing 3 @ (@@@) in the message. Called when its state is reached. {func}

Conversation

Conversation(start_state,end_state=None)
  • start_state: first State of the conversation. {State}
  • end_state: if exists, final State of the conversation. {State}
# add state to the conversation
add_state(State)
  • State: Add a State or a list of State to the conversation. {State or State list}
# add state to the conversation
add_route(state,ruotes=None,default=None,back=None)
  • state: initial State of the ruote. {State}
  • routes: routes where a state should go for every possibile data received. {value:State dict}
  • default: default route if value isn't in ruotes. {State}
  • back: route to go when the back button is pressed. {State}

AutoConvHandler

AutoConvHandler(conversation,telegram_state,back_button='Back')
  • conversation: conversation to handle. {Conversation}
  • telegram_state: Telegram state name to handle callback, text and other things. {Telegram.handler}
  • back_button: placeholder for back button. {str}
# manage conversation with update and context
manage_conversation(update,context)
  • update and context: from telegram bot function. {Telegram.update and Telegram.context}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram-autoconv-0.0.6.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file telegram-autoconv-0.0.6.tar.gz.

File metadata

  • Download URL: telegram-autoconv-0.0.6.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for telegram-autoconv-0.0.6.tar.gz
Algorithm Hash digest
SHA256 2c6ff7f486a5e5380d9d6b4d3e918c0151a89f506d28c4d0b90b4a1c2284650a
MD5 d7eea24f06b53353656fc560a6fefb39
BLAKE2b-256 6c1ef9fa99d212467cb4e404dccdceaa7ab15981b5a1536a5e352728ec3391d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page