Telegram Interfaces#

This module provides concrete implementations of the _AbstractTelegramInterface.

class LongpollingInterface(token, attachments_directory=None, interval=2, timeout=20)[source]#

Bases: _AbstractTelegramInterface

Telegram messenger interface, that requests Telegram API in a loop.

Parameters:
  • token (str) – The Telegram bot token.

  • attachments_directory (Optional[Path]) – The directory for storing attachments.

  • interval (int) – A time interval between polls (in seconds).

  • timeout (int) – Timeout in seconds for long polling.

async connect(pipeline_runner, *args, **kwargs)[source]#

Method invoked when message interface is instantiated and connection is established. May be used for sending an introduction message or displaying general bot information.

Parameters:

pipeline_runner (PipelineRunnerFunction) – A function that should process user request and return context; usually it’s a _run_pipeline() function.

class WebhookInterface(token, attachments_directory=None, host='localhost', port=844)[source]#

Bases: _AbstractTelegramInterface

Telegram messenger interface, that brings a special webserver up and registers up for listening for Telegram updates.

Parameters:
  • token (str) – The Telegram bot token.

  • attachments_directory (Optional[Path]) – The directory for storing attachments.

  • host (str) – Local host name (or IP address).

  • port (int) – Local port for running Telegram webhook.

async connect(pipeline_runner, *args, **kwargs)[source]#

Method invoked when message interface is instantiated and connection is established. May be used for sending an introduction message or displaying general bot information.

Parameters:

pipeline_runner (PipelineRunnerFunction) – A function that should process user request and return context; usually it’s a _run_pipeline() function.