Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 telegram #1559

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ Quivr, your second brain, utilizes the power of GenerativeAI to store and retrie

https://github.com/StanGirard/quivr/assets/19614572/a6463b73-76c7-4bc0-978d-70562dca71f5

## Disclaimer ⚠️

For a little while, Quivr will be only compatible with OpenAI API.

If you want to use a Local LLM please refer to [v0.0.46](https://github.com/StanGirard/quivr/releases/tag/v0.0.46).

This is due to us preparing a big feature and needing to clean the code a bit.

## Getting Started 🚀

Expand Down Expand Up @@ -112,8 +105,6 @@ Additionally, you'll need a [Supabase](https://supabase.com/) account for:
> _The `NEXT_PUBLIC_BACKEND_URL` is set to localhost:5050 for the docker. Update it if you are running the backend on a different machine._
> _To activate vertexAI with PaLM from GCP follow the instructions [here](https://python.langchain.com/en/latest/modules/models/llms/integrations/google_vertex_ai_palm.html) and update `backend/.env`- It is an advanced feature, please be expert in GCP before trying to use it_
- Change variables in `backend/.env`
- Change variables in `frontend/.env`

Expand Down
5 changes: 5 additions & 0 deletions connectors/telegram_bot/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TELEGRAM_BOT_TOKEN=XXXX
QUIVR_TOKEN=XXXX
QUIVR_CHAT_ID=1XXXX
QUIVR_BRAIN_ID=XXXX
QUIVR_URL=XXXX
73 changes: 73 additions & 0 deletions connectors/telegram_bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import logging
import os

import requests
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import (
ApplicationBuilder,
CommandHandler,
ContextTypes,
MessageHandler,
filters,
)

load_dotenv() # Load variables from .env file

logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)

telegram_bot_token = os.getenv("TELEGRAM_BOT_TOKEN", "")
quivr_token = os.getenv("QUIVR_TOKEN", "")
quivr_chat_id = os.getenv("QUIVR_CHAT_ID", "")
quivr_brain_id = os.getenv("QUIVR_BRAIN_ID", "")
quivr_url = (
os.getenv("QUIVR_URL", "https://api.quivr.app")
+ f"/chat/{quivr_chat_id}/question?brain_id={quivr_brain_id}"
)

headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + quivr_token,
}


async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="I'm Quiv's bot and can answer any question. Please ask your question.",
)


async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_message = update.message.text
response = requests.post(
quivr_url, headers=headers, json={"question": user_message}
)
if response.status_code == 200:
quivr_response = response.json().get(
"assistant", "Sorry, I couldn't understand that."
)
await context.bot.send_message(
chat_id=update.effective_chat.id, text=quivr_response
)
else:
# Log or print the response for debugging
print(f"Error: {response.status_code}, {response.text}")
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=f"Sorry, there was an error processing your request. {response.text}",
)


if __name__ == "__main__":
application = ApplicationBuilder().token(telegram_bot_token).build()

start_handler = CommandHandler("start", start)
message_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message)

application.add_handler(start_handler)
application.add_handler(message_handler)

application.run_polling()
8 changes: 8 additions & 0 deletions docs/docs/Developers/connectors/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "📲 Connect Quivr to ...",
"position": 3,
"link": {
"type": "generated-index",
"description": "Connect Quivr to anything"
}
}
34 changes: 34 additions & 0 deletions docs/docs/Developers/connectors/telegram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Telegram
---

## Load a Telegram chat

- You can export your Telegram chat history using the [Telegram Desktop](https://desktop.telegram.org/) app.
- Go to Settings > Advanced > Export Telegram data
- Select the chat you want to export
- Select the format `Machine-readable JSON`
- Click `Export`
- Rename the `json` to `<yourname>.telegram`
- Go to [Quivr.app](https://quivr.app/) and upload the file to a brain
- You can now search your Telegram chat history!

## Create a telegram bot

- Go to [BotFather](https://t.me/botfather) and create a new bot
- Copy the token
- Go to `/connectors/telegram` and copy-paste the .env.example file
- `TELEGRAM_BOT_TOKEN` The token you copied from BotFather
- `QUIVR_TOKEN` The API Key of Quivr you can find in your profile
- `QUIVR_CHAT_ID` Create a new chat in Quivr and copy the ID from the URL
- `QUIVR_BRAIN_ID` Copy the id of the brain on which you want to ask question to
- `QUIVR_URL` The URL of the **API** of the Quivr instance you want to use

Enjoy ! 🎉

<div style={{ textAlign: 'center' }}>
<video width="640" height="480" controls>
<source src="https://quivr-cms.s3.eu-west-3.amazonaws.com/quivr_telegram_bot_283a935f26.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>
</div>
2 changes: 1 addition & 1 deletion docs/docs/Developers/run_fully_local.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 4
title: 📍 Run Quivr fully locally
---

Expand Down
Loading