Telegram
Requirements
Installation
Create a Virtual Environments (venv)
python3 -m venv venv
Move into Virtual Environments workspace
. venv/bin/activate
Install all python packages
python -m pip install -r requirements.txt
Configurations
Copy example.configs.ini
to configs.ini
cp configs/example.configs/ini configs/configs.ini
How to use
Start telegram api
python3 telegram_api.py
set log levels with the logs
variable. Default = "INFO"
logs=debug python3 telegram_api.py
API Endpoints
Start a session
POST /
{
"phonenumber": "[country_code][number]"
}
- If the user already has an active session, a
200
is sent back- If the user does not have an active session a
201
is sent back and a code is sent either to their Telegram App or via SMS. You should request and provide this code to finish the start session process. See Provide Code
Provide the sent session code
PUT /
{
"phonenumber": "[country_code][number]",
"code": "[code]"
}
- If the user does not have a Telegram account a
202
is sent back. See Register user- If the code is wrong a
403
is sent back.- If the code is correct a
200
is sent back and an object
{
"phonenumber": "",
"profile": {}
}
Register user
- To continue using SWoB App, user must register a Telegram account by providing first and last name
POST /users
{
"phonenumber": "[country_code][number]",
"first_name": "",
"last_name": ""
}
- Returns
200
if successful and500
for any error
Delete user
- Deleting the record of a user stored on local server. (Does not delete user from Telegram global server).
DELETE /users
{
"phonenumber": "[country_code][number]"
}
- Returns
200
if successful and500
for any error
Get all telegram contacts
- Fetch all user's telegram contacts
POST /contacts
{
"phonenumber": "[country_code][number]"
}
- Returns
200
if successful and500
for any error
Get all active dialogs
- Fetch all user's active telegram chats
POST /dialogs
{
"phonenumber": "[country_code][number]"
}
- Returns
200
if successful and500
for any error
Send message
- Send a telegram message
- If the recipient's contact is not in the user's contact list, it will be imported automatically in order for the telegram message to be sent.
POST /message
{
"phonenumber": "[country_code][number]",
"recipient": "[country_code][number] or username or user ID",
"text": "Hello World!"
}
- If the
recipient
does not have a telegram account a422
is sent back.- Returns
200
if successful and500
for any error