Installation lib, configuration and run the bot#
Read the rules / instruction for install lib and run your bot#
Attention
If you still haven’t installed the library, use the pip command:
pip install manager_cw_bot_api
Important
Before running the file, make sure that you have received the API key from @BotFather [1], data for connecting to MySQL, business_connection_id (after enabling Business mode in @BotFather).
Instructions for connecting the bot [2]:
Create a file in your project directory:
bot.json
(example here).Create a file
main.py
(in the same directory) and go to it.Write the following code in it (replacing YOUR_TOKEN with your bot’s token received from @BotFather) (1):
1from manager_cw_bot_api import get_business_conn_and_info_conn
2
3def run() -> None:
4 print(get_business_conn_and_info_conn.gets("YOUR_TOKEN"))
5
6if __name__ == "__main__":
7 run()
Add a folder called
styles
to the directory with thebot.json
andmain.py
. Next, you need to add 5 to it files:
3 files with fonts of REGULAR, BOLD, ITALIC types,
.ttf
format.A
.png
file with a stamp/seal for CW documents and a.png
logo file. - YOU CAN GET ALL THESE FILES FOR FREE HERE.
Before executing the code, read the more detailed instructions here: Get Business connection and info connection-obj.
To find out the GIGACHAT API (RU / EN) data, you need to visit the website: https://developers.sber.ru/studio/workspaces/ and then their API, in order to get the TOKEN: https://developers.sber.ru/docs/ru/gigachat/api/reference/rest/post-token . The rest of the data (AUTH_TOKEN (for entering into the bot.json file), client_secret and client_id (id is your EMail address that you specified during registration)) you need to get it in your personal account. To do this, FOLLOW the INSTRUCTIONS of the official SBER API: https://developers.sber.ru/docs/ru/gigachat/individuals-quickstart (for phys. persons / self-employed) or https://developers.sber.ru/docs/ru/gigachat/legal-quickstart (for legal entities, sole proprietors, and organizations).
Next, once you have received the data to insert into the bot.json (bot.json) - clear the main.py and enter the following in it (2):
1"""
2Main Module of the Manager and helper-bot-manager.
3"""
4import logging
5import asyncio
6import sys
7from manager_cw_bot_api.business import run
8
9
10# Do not break the structure of func-s, classes, and components to make the modules work correctly.
11async def main() -> None:
12 """Main Function (run bot)."""
13 logging.basicConfig(
14 level=logging.INFO,
15 stream=sys.stdout,
16 format='%(levelname)s: %(asctime)s -- %(funcName)s -- %(message)s',
17 datefmt='%d-%m-%Y %H:%M:%S'
18 )
19
20 await run()
21
22
23if __name__ == '__main__':
24 asyncio.run(main())
Familiarize yourself with this rule to create the configuration (in the file) of the bot.
If you have any questions, please contact us by email: help@cwr.su.