Skip to main content

A synchronous Python library for interacting with the YoPhone API.

Project description

YoPhonePy - Python Client for YoPhone Bot API

YoPhonePy is a Python client library for interacting with the YoPhone Bot API. It provides easy-to-use methods for polling messages, handling commands, sending messages with media or buttons, and configuring webhooks.

Features

  • Poll for new messages and events
  • Register command and message handlers
  • Send messages, media, and buttons
  • Configure webhooks
  • Get bot and webhook information

Installation

Install the library from PyPI:

pip install yophonepy

Getting Started

1. Obtain an API Key

Register on the YoPhone platform to get your API key.

2. Set API Key

You can set your API key as an environment variable:

export YOPHONE_API_KEY="your_api_key_here"

Or pass it directly to the YoPhonePy class:

from yophonepy import YoPhonePy

bot = YoPhonePy(api_key="your_api_key_here")

3. Write Your Bot

from yophonepy import YoPhonePy, Message

bot = YoPhonePy(api_key="your_api_key_here")

@bot.command_handler("start")
def start_handler(msg: Message):
    bot.send_message(msg.chat_id, "Hello! How can I assist you today?")

@bot.message_handler
def echo_handler(raw_data):
    msg = Message.from_dict(raw_data)
    bot.send_message(msg.chat_id, f"You said: {msg.text}")

if __name__ == "__main__":
    bot.start_polling(interval=2)

Alternative Usage Example

You can also register handlers and initialize the bot programmatically:

from yophonepy import YoPhonePy

def start_command(message: Message):
    start_text = f"""
    Welcome to YoPhonePy Bot, {message.sender.first_name}! \n
    """
    bot.send_message(message.chat_id, start_text)


def help_command(message: Message):
    help_text = f"""
    Welcome to YoPhonePy Bot, {message.sender.first_name}! \n
    """
    bot.send_message(message.chat_id, help_text)


if __name__ == "__main__":
    bot = YoPhonePy(
        api_key=your_api_key_here
    )

    bot.command_handler("start")(start_command)
    bot.command_handler("help")(help_command)

    # Start polling for updates
    bot.start_polling(interval=3)

Sending Media and Buttons

Send Files:

bot.send_files(chat_id="123456", file_paths=["/path/to/file1.png"], caption="Here is your file!")

Send Buttons:

bot.send_message_with_buttons(
    chat_id="123456",
    text="Choose an option:",
    options=[{"text": "Option 1", "value": "opt1"}, {"text": "Option 2", "value": "opt2"}]
)

Webhooks

Set a Webhook:

bot.set_webhook("https://yourdomain.com/webhook")

Get Webhook Info:

bot.get_webhook_info()

Remove Webhook:

bot.remove_webhook()

Utilities

  • configure_commands(commands: List[Dict[str, str]]) — Set available slash commands
  • get_bot_info() — Fetch bot metadata
  • get_channel_user_status(channel_id, user_id) — Get user's status in a channel

License

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


For more information, refer to the official YoPhone API Documentation.

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

yophonepy-0.1.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

yophonepy-0.1.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file yophonepy-0.1.2.tar.gz.

File metadata

  • Download URL: yophonepy-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for yophonepy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8c4a84ca33887f2362f41066c0ca6b18b1a5e6d2e5746395b672fd8364aab355
MD5 fa383c168a0f6b27ad5e77617b90cbaa
BLAKE2b-256 764d4e5e3896b1b930659466cb29c71ce276d07d0fa018ff97fde1fda33b9a10

See more details on using hashes here.

File details

Details for the file yophonepy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: yophonepy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for yophonepy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 325b9a22a27681f0250f0bd4c0de6c9db9d6b5c8599d9fcf60d462068b64575c
MD5 a0d23f6c47ad7fdd0291ba7f4266f2a5
BLAKE2b-256 ac5b2cae10490c01e6c9dcd8ebe4e4a6909f69166be7e691b2ee38429832995b

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