Создавайте ботов, автоматизируйте задачи и расширяйте мессенджер
Создание бота для ONEMIX занимает несколько минут:
/newbotpip install onemix-bot
from onemix_bot import OnemixBot
bot = OnemixBot(
token="YOUR_BOT_TOKEN",
api_url="https://your-server.com"
)
@bot.command("start")
def handle_start(message):
bot.send_message(
chat_id=message["bot_chat_id"],
text="Привет! Я бот ONEMIX"
)
@bot.on_message()
def handle_message(message):
bot.send_message(
chat_id=message["bot_chat_id"],
text=f"Вы написали: {message['content']}"
)
bot.run()
Команды @botfather:
/newbot — Создать бота/mybots — Список ботов/setname — Изменить имя/setdescription — Описание/setcommands — Команды/deletebot — Удалить/token — Токен{"name":"My Bot","username":"my_cool_bot","description":"Мой бот","category":"utility"}
{"id":"uuid","username":"my_cool_bot","api_token":"uuid:hex","message":"Бот @my_cool_bot создан!"}
bot или _bot. Минимум 5 символов.Заголовок для Bot API:
Authorization: Bot YOUR_BOT_TOKEN
{"chat_id":"bot-chat-uuid","text":"Привет от бота!"}{"ok":true,"message_id":"msg-uuid"}
{"ok":true,"result":[{"id":"msg-uuid","bot_chat_id":"chat-uuid","sender_type":"user","content":"/start","user_id":"user-uuid","user_name":"Иван"}]}
{"url":"https://your-server.com/webhook","secret":"optional"}
Сервер отправит POST:
{"update_type":"message","message":{"id":"msg-uuid","bot_chat_id":"chat-uuid","content":"Текст","user_id":"user-uuid","user_name":"Иван"}}
{"commands":[{"command":"start","description":"Запуск"},{"command":"help","description":"Помощь"}]}
onemix-botfrom onemix_bot import OnemixBot
bot = OnemixBot(token="TOKEN", api_url="https://server.com")
me = bot.get_me() # Информация о боте
bot.send_message(chat_id, text) # Отправка
bot.reply(msg, text) # Ответ на сообщение
updates = bot.get_updates(limit=50) # Получение обновлений
bot.set_webhook("https://...") # Установить вебхук
bot.set_commands([...]) # Установить команды
bot.run() # Polling loop
@bot.command("start")
def on_start(msg):
bot.reply(msg, "Добро пожаловать!")
@bot.on_message()
def on_text(msg):
bot.reply(msg, f"Эхо: {msg['content']}")
@bot.on_message(pattern=r"привет|здравствуй")
def on_hello(msg):
bot.reply(msg, "Привет!")
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhook", methods=["POST"])
def webhook():
bot.process_update(request.json)
return "ok"
bot.set_webhook("https://your-server.com/webhook")
app.run(port=5000)
from onemix_bot import OnemixBot
bot = OnemixBot(token="TOKEN", api_url="https://server.com")
@bot.command("start")
def start(msg):
bot.send_message(msg["bot_chat_id"], "Отправь текст.")
@bot.on_message()
def echo(msg):
bot.send_message(msg["bot_chat_id"], msg["content"])
bot.run()
import threading, time
from onemix_bot import OnemixBot
bot = OnemixBot(token="TOKEN", api_url="https://server.com")
@bot.command("remind")
def remind(msg):
parts = msg["content"].split(" ", 2)
if len(parts) < 3:
bot.reply(msg, "Формат: /remind [мин] [текст]")
return
mins, text = int(parts[1]), parts[2]
cid = msg["bot_chat_id"]
def do():
time.sleep(mins * 60)
bot.send_message(cid, f"Напоминание: {text}")
threading.Thread(target=do, daemon=True).start()
bot.reply(msg, f"Напомню через {mins} мин.")
bot.run()
import openai
from onemix_bot import OnemixBot
bot = OnemixBot(token="TOKEN", api_url="https://server.com")
client = openai.OpenAI(api_key="sk-...")
@bot.on_message()
def ai(msg):
r = client.chat.completions.create(
model="gpt-4",
messages=[{"role":"user","content":msg["content"]}],
max_tokens=500)
bot.send_message(msg["bot_chat_id"],
r.choices[0].message.content)
bot.run()