The OneChat Python library provides an interface for sending messages, broadcasting messages to multiple users, sending location information, sending stickers, and sending files through the OneChat API.
Project description
OneChat Python Library Documentation
Overview
The OneChat Python library provides an interface for sending messages, broadcasting messages to multiple users, sending location information, sending stickers, and sending files through the OneChat API.
Features
- Send Messages: Send messages to individual users or groups.
- Send Files: Send files to users for easy sharing.
- Send WebView: Send a webview to users for interactive content.
- Broadcast Messages: Send messages to multiple recipients at once.
- Send Locations: Share geographical locations with users.
- Send Stickers: Send sticker messages to users.
- Fetch Friends and Groups: Retrieve the complete list of friends and groups for a bot.
- List All Friends: Get a list of all friends associated with the bot.
- List Friend IDs: Retrieve the One IDs of all friends for easy identification.
- List All Groups: Get a list of all groups associated with the bot.
- List Group IDs: Retrieve the IDs of all groups for further actions.
Installation
To install the OneChat Python library, run the following command
pip install one-chat-api
Usage
To use the OneChat library, follow these steps
Import the Library
from one_chat import (
init,
send_message,
send_file,
broadcast_message,
send_location,
send_sticker,
fetch_friends_and_groups,
list_all_friends,
list_friend_ids,
list_all_groups,
list_group_ids,
)
or you can import all functions at once
from one_chat import *
Initialize the Library
Before using the functions, you need to initialize the library with your authorization token, default recipient, and bot id
init(
"YOUR_AUTHORIZATION_TOKEN", # Replace with your token
"DEFAULT_RECIPIENT_ID", # Replace with user ID or group ID
"YOUR_BOT_ID" # Replace with your bot ID
)
Send Messages
You can send a message to a specific user or group
response = send_message(message="Hello One!")
print("Send Message response:", response)
Send Files
You can send a file to a specific user or group
response = send_file(file_path="results.csv")
print("Send File response:", response)
[!TIP] You can now send images using the send_file function, making it easier to share media files with your users!
Send WebView
response = send_webview(url="https://google.com/")
print("Send Webview response:", response)
[!IMPORTANT] You need to specify the Protocol (http:// or https://) in the URL
Broadcast Messages
To send a message to multiple recipients
[!IMPORTANT] recipients must be a list of user IDs only !!! cannot be a group ID
response = broadcast_message(message="Hello Multi!", to=["USER_ID_1", "USER_ID_2"])
print("Send Message Multi response:", response)
Send Locations
To share a location
response = send_location(latitude=13.7563, longitude=100.5018, address="Bangkok, Thailand")
print("Send Location Response:", response)
Send Stickers
To send a sticker
response = send_sticker(sticker_id="YOUR_STICKER_ID")
print("Send Sticker Response:", response)
Example
Here’s a complete example of how to use the library
from one_chat import *
def main():
# Initialize OneChat with your token, recipient, and bot ID
init(
"YOUR_AUTHORIZATION_TOKEN",
"DEFAULT_RECIPIENT_ID", # Send to (One ID) or (Group ID)
"YOUR_BOT_ID" # Bot ID
)
# Send a single message
resp_msg = send_message(message="Hello One!")
print("Send Message response:", resp_msg)
# Send a file
resp_file = send_file(file_path="results.csv")
print("Send File response:", resp_file)
# Send a webview
resp_webview = send_webview(url="https://google.com/")
print("Send Webview response:", resp_webview)
# Broadcast a message to multiple users
resp_msg_multi = broadcast_message(message="Hello Multi!", to=["USER_ID_1", "USER_ID_2"])
print("Send Message Multi response:", resp_msg_multi)
# Send a location
resp_location = send_location(latitude=13.7563, longitude=100.5018, address="Bangkok, Thailand")
print("Send Location Response:", resp_location)
# Send a sticker
resp_sticker = send_sticker(sticker_id="YOUR_STICKER_ID")
print("Send Sticker Response:", resp_sticker)
# Get a list of friends and groups
friends_and_groups = fetch_friends_and_groups() # you can use fetch_friends_and_groups("BOT_ID") to get friends and groups of another bot
print("Friends and Groups:", friends_and_groups)
# Get a list of friends
friends = list_all_friends() # you can use list_all_friends("BOT_ID") to get friends of another bot
print("Friends:", friends)
# Get the One ID of a friend
one_id = list_friend_ids() # you can use list_friend_ids("BOT_ID") to get one id of a friend of another bot
print("One ID of Friend:", one_id)
# Get a list of groups
groups = list_all_groups() # you can use list_all_groups("BOT_ID") to get groups of another bot
print("Groups:", groups)
# Get the group ID of a group
group_id = list_group_ids() # you can use list_group_ids("BOT_ID") to get group id of a group of another bot
print("Group ID of Group:", group_id)
if __name__ == "__main__":
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
Built Distribution
File details
Details for the file one_chat_api-0.2.15.tar.gz
.
File metadata
- Download URL: one_chat_api-0.2.15.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f31190ad4d4e83810eb10e026c0a4cc17351f07068fdbb75b680b2f09a7af24 |
|
MD5 | 61ce81c021a0b0209c32e90656c24677 |
|
BLAKE2b-256 | a83ed49a6ef0f9e0f0ad75d55509972d5ccb587fc67fd01a7d998c1e20b3641f |
File details
Details for the file one_chat_api-0.2.15-py3-none-any.whl
.
File metadata
- Download URL: one_chat_api-0.2.15-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a55c7c4af1359560fe03f9077f7654d6397f7978a42a3ac25d51e9756302f96f |
|
MD5 | c24c23fda6a3fc251a574d562c820102 |
|
BLAKE2b-256 | 800762c80256e1799e1fcb526dfb1d3c6928ca58877c498bbe0098b07e76fc47 |