Skip to main content

Python client for VK MAX messenger (OneMe)

Project description

python-max-client

Python client library for VK MAX messenger (OneMe)

PyPI version Python 3.9+ License: MIT

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 python-max-client?

This is a comprehensive client library for VK MAX messenger, allowing you to create userbots, custom clients, and automated solutions.
The library provides a simple and intuitive API for interacting with the MAX messenger protocol.

Features

  • 🔐 Authentication: Support for SMS and token-based login
  • 💬 Messaging: Send, receive, and edit messages
  • 👥 Users & Groups: Manage users, groups, and channels
  • 🔄 Real-time: WebSocket-based real-time communication
  • 🛠️ Extensible: Easy to extend with custom functionality
  • 📱 Userbot Support: Create powerful userbots and automation

Installation

The package is available on PyPI:

pip install python-max-client

Or install from source:

git clone https://github.com/huxuxuya/python-max-client.git
cd python-max-client
pip install -e .

Usage

More in examples

import asyncio
import logging

import requests
import sys

from python_max_client.client import MaxClient
from python_max_client.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())

Documentation

Examples

Check out the examples directory for more usage examples:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

huxuxuya - huxuxuya@gmail.com

Acknowledgments

  • Original project by nsdkinx
  • VK Group for developing the MAX messenger platform

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

python_max_client-1.0.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

python_max_client-1.0.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file python_max_client-1.0.0.tar.gz.

File metadata

  • Download URL: python_max_client-1.0.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for python_max_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 95041b5d92a50fb8b9d9250b4817fb3e15791dc17034925ee08d84fc7e6eb932
MD5 2ba539af8023fa552171b490f0c78eba
BLAKE2b-256 a8fd8e602547fdfa641bddc46b06b5322d0f319b8e434f30600df1694e212b6b

See more details on using hashes here.

File details

Details for the file python_max_client-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_max_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e572c79f83b2c788fe2b2fc4e6ce8e8c2c53763f3dececbda272829309dceb9
MD5 b8fb7471e71f85bd482f98b497ccb6ca
BLAKE2b-256 b1785dc5b4b8f2b4dfcde38a89572e3f454cd654d26b66c04b189b33c9bb68b1

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