Examples
Chat bots
Slack and Telegram bots that remember each user and channel.
Every bot is the same shape: on each message, recall what you know about this user or channel, answer with it in the prompt, store the exchange. One process_turn call does the recall and the store. These use the hosted API; the self-host swap is one line (shown at the bottom). Discord is over in Frameworks & tools.
Slack (Bolt, hosted API)
Terminal
pip install slack_bolt requests
export MENTEDB_API_KEY=mdb_your_key_here
export SLACK_BOT_TOKEN=xoxb-...
export SLACK_APP_TOKEN=xapp-...Python
import os, requests
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
API = "https://api.mentedb.com/v1/process_turn"
HEADERS = {"Authorization": f"Bearer {os.environ['MENTEDB_API_KEY']}"}
app = App(token=os.environ["SLACK_BOT_TOKEN"])
memory, turns = {}, {} # per-channel context + turn counter
@app.event("message")
def on_message(event, say):
if event.get("bot_id"):
return
ch = event["channel"]
context = "\n".join(m["content"] for m in memory.get(ch, []))
reply = call_your_llm(
system=f"You are a helpful teammate.\nWhat you remember:\n{context}",
user=event["text"],
)
say(reply)
# Store the exchange; context comes back for the next message in this channel.
turn = turns.get(ch, 0)
result = requests.post(API, headers=HEADERS, json={
"user_message": event["text"],
"assistant_response": reply,
"turn_id": turn,
"project_context": f"slack:{ch}", # advisory tag, not isolation (use user_id for that)
}).json()
memory[ch] = result["context"]
turns[ch] = turn + 1
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()Telegram (hosted API)
Terminal
pip install python-telegram-bot requests
export MENTEDB_API_KEY=mdb_your_key_here
export TELEGRAM_TOKEN=...Python
import os, requests
from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes, filters
API = "https://api.mentedb.com/v1/process_turn"
HEADERS = {"Authorization": f"Bearer {os.environ['MENTEDB_API_KEY']}"}
memory, turns = {}, {}
async def on_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
text = update.message.text
context = "\n".join(m["content"] for m in memory.get(chat_id, []))
reply = call_your_llm(system=f"What you remember:\n{context}", user=text)
await update.message.reply_text(reply)
turn = turns.get(chat_id, 0)
result = requests.post(API, headers=HEADERS, json={
"user_message": text,
"assistant_response": reply,
"turn_id": turn,
"project_context": f"telegram:{chat_id}",
}).json()
memory[chat_id] = result["context"]
turns[chat_id] = turn + 1
app = ApplicationBuilder().token(os.environ["TELEGRAM_TOKEN"]).build()
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, on_message))
app.run_polling()Self-hosted: swap the transport
Any of these bots run against the embedded engine with no network. Replace the REST POST with the SDK call; result.context carries the same memories (attribute access instead of dict keys).
Python
from mentedb import MenteDB
db = MenteDB("./bot-memory") # data on local disk
# inside your handler, instead of requests.post(...):
result = db.process_turn(
user_message=text,
assistant_response=reply,
turn_id=turn,
project_context=f"slack:{ch}",
)
memory[ch] = [m.content for m in result.context]