Package: vk-teams-async-bot
Table of ContentsIntroductionInstallingImplemented methods in this libraryExamplesBasic initializationSend messagesWithout formattingMarkdownV2InlineKeyboardMiddlewareIntroductionThis library provides the ability to interact with VK Teams Bot API.API description  -https://teams.vk.com/botapi/Метаботfor creating a bot and getting a token.Installingpipinstall-Uvk-teams-async-bot# ORpoetryaddvk-teams-async-botImplemented methods in this librarymethodENDPOINTEXISTSname in libraryGET/self/get✅bot.self_getGET/messages/sendText✅bot.send_textGET/messages/sendTextWithDeeplink❌GET/messages/sendFile✅bot.send_file_by_idPOST/messages/sendFile✅bot.send_fileGET/messages/sendVoice✅bot.send_voicePOST/messages/sendVoice✅bot.send_voice_by_idGET/messages/editText✅bot.edit_textGET/messages/deleteMessages✅bot.delete_msgGET/messages/answerCallbackQuery✅bot.answer_callback_queryExamplesBasic initializationimportasynciofromvk_teams_async_bot.botimportBotfromvk_teams_async_bot.eventsimportEventfromvk_teams_async_bot.filterimportFilterfromvk_teams_async_bot.handlerimportCommandHandlerapp=Bot(bot_token="TOKEN",url="URL")asyncdefcmd_start(event:Event,bot:Bot):awaitbot.send_text(chat_id=event.chat.chatId,text="Hello")app.dispatcher.add_handler(CommandHandler(callback=cmd_start,filters=Filter.command("/start")),)asyncdefmain():awaitapp.start_polling()if__name__=="__main__":asyncio.run(main())Send messagesWithout formattingasyncdefcmd_start(event:Event,bot:Bot):awaitbot.send_text(chat_id=event.chat.chatId,text="Hello")awaitbot.send_text(chat_id=event.chat.chatId,text="<b>Hello</b>")awaitbot.send_text(chat_id=event.chat.chatId,text="*Hello*")Result:MarkdownV2parse_mode=ParseMode.MARKDOWNV2All special characters that do not represent the beginning or end of the style must be escaped using a backslash \Methods MarkdownV21. *hello*   -  bold
2. _hello_   -  italic
3. __hello__ -  underline
4. ~hello~   -  strikethrought
5. [hello](https://example.com) - hyperlinked text
6. @\[user@company\]            - to mention the VK Teams user
7. ```hello```                  - inline code
8. ```python print("hello") ``` - multiline block code
9.  Ordered list:
    1. First element
    2. Second element
10. Unordered list:
    - First element
    - Second element
11. Quote:
    >Begin of quote
    >End of quoteasyncdefcmd_start(event:Event,bot:Bot):text=\"""*hello*_hello___hello__"""awaitbot.send_text(chat_id=event.chat.chatId,text=text,parse_mode=ParseMode.MARKDOWNV2)Result:InlineKeyboardfromvk_teams_async_bot.constantsimportStyleKeyboardfromvk_teams_async_bot.handlerimportCommandHandlerfromvk_teams_async_bot.helpersimportInlineKeyboardMarkup,KeyboardButtondefkeyboad_start_menu():keyboard=InlineKeyboardMarkup(buttons_in_row=3)keyboard.add(KeyboardButton(text="🛠 first button",callback_data="cb_one",style=StyleKeyboard.PRIMARY,),KeyboardButton(text="🕹 second button",callback_data="cb_two",style=StyleKeyboard.BASE,),KeyboardButton(text="🌐 third button",url="https://example.com/",style=StyleKeyboard.ATTENTION,),)returnkeyboardasyncdefcmd_start(event:Event,bot:Bot):text="""hello"""awaitbot.send_text(chat_id=event.chat.chatId,text=text,inline_keyboard_markup=keyboad_start_menu(),)You can specify the number of buttons in a rowInlineKeyboardMarkup(buttons_in_row=1)MiddlewareYou can check the incoming request or add any data for further use in handlers.Check the access rights of the user or groupfromvk_teams_async_bot.middlewareimportMiddlewareclassAccessMiddleware(Middleware):asyncdefhandle(self,event,bot):allowed_chats=["id@chat.agent",]ifevent.chat.chatIdnotinallowed_chats:text=f"Does not have rights to use the bot -{event.chat.chatId}"awaitbot.send_text(chat_id=event.chat.chatId,text=text)raisePermissionError(text)returneventasyncdefmain():app.dispatcher.middlewares=[AccessMiddleware(),]awaitapp.start_polling()if__name__=="__main__":asyncio.run(main())Add a user or group roleLet's imagine that we have a data source on our side with roles or user rights that we want to use to access a specific menu or handlerfromvk_teams_async_bot.middlewareimportMiddlewareclassUserRoleMiddleware(Middleware):asyncdefhandle(self,event,bot):roles={"id@chat.agent":"admin",}event.middleware_data.update({"role":roles.get(event.chat.chatId)})logger.debug("UserRoleMiddleware role for{chatID}-{role}".format(chatID=event.chat.chatId,role=event.middleware_data.get("role")))returneventasyncdefmain():app.dispatcher.middlewares=[UserRoleMiddleware(),]awaitapp.start_polling()if__name__=="__main__":asyncio.run(main())