Skip to main content

KenarBot: A Python SDK for building Kenar messaging bots with an intuitive, teleBot-inspired syntax.

Project description

KenarBot

PyPI version License: MIT Python Versions codecov

A Python SDK for creating and managing Kenar messaging bots. KenarpyBot provides a simple, intuitive interface inspired by teleBot's syntax, making it easy for developers familiar with Telegram bot development to create bots for the Kenar platform.

What is Kenar Divar?

Kenar Divar is Divar's official platform that provides APIs for developers to create plugins and integrations with Divar. These APIs enable functionality like sending and receiving messages, editing posts, patching add-ons on posts and etc... , you should also checkput Kenar Divar Panel

Features

  • 🚀 Simple, teleBot-inspired syntax
  • 📨 Easy message handling and routing
  • 🔄 Built-in support for Kenar's messaging endpoints
  • ⚡ Flask-based webhook handling
  • ⚙️ Straightforward bot configuration

Installation

pip install kenarbot

Quick Start Example

Here's a simple example demonstrating how to create a bot that responds to messages containing "hello":

import os

from kenarBot import KenarBot
from kenarBot.types import ChatBotMessage

# Initialize your API key from Kenar platform
DIVAR_API_KEY = os.getenv("DIVAR_API_KEY")
DIVAR_IDENTIFICATION_KEY = os.getenv("DIVAR_IDENTIFICATION_KEY")

# Create a bot instance
bot = KenarBot(DIVAR_IDENTIFICATION_KEY, "/webhook", DIVAR_API_KEY)

# Define a message handler that responds to messages containing "hello"
@bot.message_handler(regexp="hello")
def handle_hello(chatbot_message: ChatBotMessage):
    # Send a response back to the same conversation
    bot.send_message(chatbot_message.conversation_id, f"Hi, my name is AmazingKenarBot")

if __name__ == "__main__":
    # Start the bot
    bot.run()

This example shows:

  • How to initialize the bot with your API key
  • How to create a message handler using decorators
  • How to respond to specific messages using regular expressions
  • How to send messages back to conversations

Key Components:

  1. Bot Initialization:

    • Create a KenarBot instance with your app name, webhook path, and API key
    • The webhook path is where your bot will receive updates
  2. Message Handler:

    • Use the @bot.message_handler decorator to define message handlers
    • The regexp parameter allows you to filter messages based on regular expressions
    • Other handler options are available (commands, content types, etc.)
  3. Sending Messages:

    • Use bot.send_message() to send responses
    • Requires the conversation ID and the message text
  4. Running the Bot:

    • Call bot.run() to start the bot
    • This will start a Flask server to handle incoming webhook requests

Important Notes:

  • Keep your API key secure and never commit it to version control
  • Consider using environment variables for sensitive data
  • The bot runs on Flask, so it needs to be hosted on a server accessible to Kenar

Documentation

Available Methods

  • bot.send_message(conversation_id, text): Send a message to a conversation
  • bot.message_handler(regexp=""): Decorator for handling messages matching a regex pattern
  • bot.run(): Start the bot's webhook server

Contributing

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

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

Support

Acknowledgments

Author

Mobin Pourabedini (@Mobin-Pourabedini)


Made with ❤️ for the Kenar community

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

kenarbot-0.0.5.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

kenarBot-0.0.5-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file kenarbot-0.0.5.tar.gz.

File metadata

  • Download URL: kenarbot-0.0.5.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for kenarbot-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a5a425a704f0c36fc24db623f8f49329a0c087511d9c9a57a632a5220ea4c1b5
MD5 3a027c9b78f579b7c0cb7d9107b021e4
BLAKE2b-256 761ddeb1fdb46c9148af32c9fef070fb81ebaf2afaa348989d91899c5a841000

See more details on using hashes here.

File details

Details for the file kenarBot-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: kenarBot-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for kenarBot-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5186558f9fb221c844ec1c12efa5c3794a246955e35d692526dd8e753e9ce001
MD5 85a7ee9d1b6ca807d80885f85b84104f
BLAKE2b-256 8f6cb8c7841802ca223bcf7c99dd7bab787b1fd81975b65873cfe3e5824650f2

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