Skip to main content

Python client for MAX messenger

Project description

vkmax

Python user client for VK MAX messenger (OneMe)

What is VK MAX?

MAX (internal code name OneMe) is another project by the Russian government in an attempt to create a unified domestic messaging platform with features such as login via the government services account (Gosuslugi/ESIA).
It is developed by VK Group.

What is vkmax?

This is a client library for MAX, allowing to create userbots and custom clients.
An example of a simple userbot that retrieves weather can be found at examples/weather-userbot.

Installation

The package is available on PyPI
pip install vkmax

Usage

More in examples

import asyncio
import logging

import requests
import sys

from vkmax.client import MaxClient
from vkmax.functions.messages import edit_message

from pathlib import Path


async def get_weather(city: str) -> str:
    response = requests.get(f"https://ru.wttr.in/{city}?Q&T&format=3")
    return response.text


async def packet_callback(client: MaxClient, packet: dict):
    if packet['opcode'] == 128:
        message_text: str = packet['payload']['message']['text']
        if message_text not in ['.info', '.weather']:
            return

        if message_text == ".info":
            text = "Userbot connected"

        elif ".weather" in message_text:
            city = message_text.split()[1]
            text = await get_weather(city)

        await edit_message(
            client,
            packet["payload"]["chatId"],
            packet["payload"]["message"]["id"],
            text
        )


async def main():
    client = MaxClient()

    await client.connect()

    login_token_file = Path('login_token.txt')

    if login_token_file.exists():
        login_token_from_file = login_token_file.read_text(encoding='utf-8').strip()
        try:
            await client.login_by_token(login_token_from_file)
        except:
            print("Couldn't login by token. Falling back to SMS login")

    else:
        phone_number = input('Enter your phone number: ')
        sms_login_token = await client.send_code(phone_number)
        sms_code = int(input('Enter SMS code: '))
        account_data = await client.sign_in(sms_login_token, sms_code)

        login_token = account_data['payload']['tokenAttrs']['LOGIN']['token']
        login_token_file.write_text(login_token, encoding='utf-8')

    await client.set_callback(packet_callback)

    await asyncio.Future()  # run forever


if __name__ == "__main__":
    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

vkmax-1.0.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vkmax-1.0.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file vkmax-1.0.2.tar.gz.

File metadata

  • Download URL: vkmax-1.0.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for vkmax-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a7d23be4d39b187bb9671d2d1d61061d9ca25ec5a37c7dd8129f262b6ad07e3e
MD5 80c051f55a7f53a7d66c0600a579067e
BLAKE2b-256 e925ef4d816a0e148e3c81bb4081cea6c03a5f95cd34e57e0fc560aad43e95be

See more details on using hashes here.

File details

Details for the file vkmax-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: vkmax-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for vkmax-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd4783d4f192c035168920b6e2705176afe59c41830c8c90dd7448ad25378462
MD5 09ab5986751bf4a7e0cf41ff9134581a
BLAKE2b-256 24032368e62e89c48c959ed62d96d658d7ab311b8f0966a7fc5aa4cb6e373ff8

See more details on using hashes here.

Supported by

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