Welcome to action-react’s documentation!

Overview

action-react specifically listens to an account in a Telegram chat and makes corresponding http calls given the content of the message. This is inspired by tuixue.online-visa, a tool that periodically checks and publishes US consulate visa appointment availabilities across the world.

A possible application of this tool is to use it to listen to a Telegram bot publishing messages about new visa appointments, and makes http calls to the consulate appointment service to grab the desired spot.

Installation

Install the library’s dependencies and build the library using:

pip install action-react

Usage

In your code, begin by importing the package:

from action-react import main

You can connect it to a telegram chat using:

main(api_id, api_hash, phone, username, target_date, cities)

For example, you can use main("123", "hash123", "+12345678901", "username", datetime.date(2022,2,2), ["boston", "houston"]) to start the function. While the script containing main is running, you’ll get a prompt enter entity (telegram URL or entity id) to listen to, to which you can enter the listener target, for example https://t.me/tuixue_h_visa. Afterwards, if the client is successfully connected to the chat, the script will print out logs like the ones below.

received message: London H: 5/17 -> 4/26
received message: Vancouver H: 2024/7/18 -> 2024/7/10
received message: Dublin H: 4/27 -> 4/21
received message: Guadalajara H: 7/25 -> 6/28
received message: Paris H: 5/2 -> 4/7
received message: Paris H: 5/2 -> 4/20

If a good date has been found, something like found a good appointment in Paris on 2023-05-16 will be printed.

Alternatively, you can directly run python main.py after setting up the configurations in config.ini. The functionality will be the same as described above as the usage of the main function.

API reference

action_react.main.check_message(message, target_date, cities)

Process incoming telegram messages

Parameters
  • message (str, message) –

  • target_date (date, the date upon which to improve) –

  • cities (list of city names) –

Returns

  • A tuple. The first element indicates whether a good date

  • can be retrieved from the message. The second element is None

  • if the first element is False. Otherwise, it’s a tuple whose

  • first element is the date and the second element is the city

action_react.main.connect_to_telegram(username, api_id, api_hash, phone)

Connect to telegram

Parameters
  • username (str, user name) –

  • api_id (str, telegram api id) –

  • api_hash (str, telegram api hash) –

  • phone (str, phone number) –

Returns

client

Return type

telegram client

action_react.main.get_target_channel()

Read telegram channel to listen to from command line.

Returns

listening_channel

Return type

channel name

action_react.main.main(api_id, api_hash, phone, username, target_date, cities)

Main function that acts on a target telegram message. It runs until interrupted.

Parameters
  • api_id (str, telegram api id) –

  • api_hash (str, telegram api hash) –

  • phone (str, telegram phone number) –

  • username (str, telegram username) –

  • target_date (date, the date upon which to improve) –

  • cities ([str], list of city names) –

action_react.main.read_configs(file_name)

Read configuration parameters from a file.

Parameters

file_name (str, relative path from the root directory of this package) –

Returns

  • api_id (telegram api id)

  • api_hash (telegram api hash)

  • phone (telegram phone number)

  • username (telegram username)

  • target_date (the date upon which to improve)

  • cities (list of city names)

action_react.react.process_with_city_and_date(reaction, object, city, date)

Process string object with city and/or date

Parameters
  • reaction (json object, reaction) –

  • object (str, string to be updated) –

  • city (str, target city) –

  • date (date, target date) –

Returns

object

Return type

updated object

action_react.react.react(date, city)

React

Parameters
  • city (str, target city) –

  • date (date, target date) –

Indices and tables