File size: 1,188 Bytes
9f99fe2
 
 
 
 
 
 
 
 
 
 
7c3e9f4
9f99fe2
 
 
 
0c384f5
9f99fe2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Define your LangChain chatbot."""
import re
from abc import abstractmethod

from telegram import Update
from telegram.ext import (
    ConversationHandler,
    CallbackContext,
)

from agent.tools.text_summary import ConversationSummary
from agent.tools.conversation import Conversation

SELECT_COMMAND, GET_TEXT = range(2)


class BuddyAgentBot(ConversationSummary,  Conversation):
    def is_verbose_logging_enabled(self):
        return True

    def send_message(self, message: str, update: Update) -> str:
        """Send a message to Telegram.

        Note: This is a private endpoint that requires authentication."""
        update.message.reply_text(message)
        return "ok"

    def _invoke_later(self, delay_ms: int, message: str, chat_id: str):
        self.invoke_later(
            "send_message",
            delay_ms=delay_ms,
            arguments={
                "message": message,
                "chat_id": chat_id,
            },
        )

    async def cancel(update: Update, context: CallbackContext) -> int:
        """Cancel the conversation."""
        await update.message.reply_text("Oops, glad to help you.")
        return ConversationHandler.END