Skip to main content

Common interface for vk/telegram api calls

Project description

This package allows to interact with vk and telegram API using the same interface.

It’s main purpose is to simply switch 🕹 between services while developing bots.

Setup

Firstly you should export environment variables. Create .env file and fill vars:

TELEGRAM_TOKEN=telegram_token
VK_TOKEN=vk_token

Example

Upload Images to vk and tg.

import asyncio

import aiofiles

from adapters.factory import create_adapter
from adapters.enums import AdapterType
from dotenv import load_dotenv
load_dotenv()

tg_adapter = create_adapter(adapter_type=AdapterType.TELEGRAM)
vk_adapter = create_adapter(adapter_type=AdapterType.VK)


async def main():
    async with aiofiles.open('test.png', mode='rb') as data:
        content = await data.read()
        await asyncio.gather(*[
                tg_adapter.send_image(chat_id=-195789610, image=content),
                vk_adapter.send_image(chat_id=2000000006, image=content)
        ])

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async-bot-api-adapters-0.0.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page