KenarBot: A Python SDK for building Kenar messaging bots with an intuitive, teleBot-inspired syntax.
Project description
KenarBot
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
Examples
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:
-
Bot Initialization:
- Create a
KenarBotinstance with your app name, webhook path, and API key - The webhook path is where your bot will receive updates
- Create a
-
Message Handler:
- Use the
@bot.message_handlerdecorator to define message handlers - The
regexpparameter allows you to filter messages based on regular expressions - Other handler options are available (commands, content types, etc.)
- Use the
-
Sending Messages:
- Use
bot.send_message()to send responses - Requires the conversation ID and the message text
- Use
-
Running the Bot:
- Call
bot.run()to start the bot - This will start a Flask server to handle incoming webhook requests
- Call
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 conversationbot.message_handler(regexp=""): Decorator for handling messages matching a regex patternbot.run(): Start the bot's webhook server
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Create an Issue
- Send an email to realmobinpourabedini@gmail.com
Acknowledgments
- Inspired by the pyTelegramBotAPI project
- Thanks to the open-platform team
Author
Mobin Pourabedini (@Mobin-Pourabedini)
Made with ❤️ for the Kenar community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kenarbot-0.1.1.tar.gz.
File metadata
- Download URL: kenarbot-0.1.1.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8b0b73bbcac1ae61fb824c1f095b30c5796f771ced68aa0c8032fbe50d292c4
|
|
| MD5 |
c3a14307d5e230db3a37704c7d493e19
|
|
| BLAKE2b-256 |
ca5526322638bcd96b8bd028170ab55f8d3b6930d2dcd2ced579f5b761b1a7c6
|
File details
Details for the file kenarbot-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kenarbot-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e9bdb864b50c8626241623ed34d77540041caba802beefe90dbffb38652baf7
|
|
| MD5 |
d5d62187364aed1790cad07e0b745c26
|
|
| BLAKE2b-256 |
95e7cad5ed1c8a60089aadd91f79fec37f58b7556c50d8ccbdc2816f7528541d
|