"""Define your LangChain chatbot.""" import re from abc import abstractmethod from telegram import Update import telegram from telegram.ext import ( ConversationHandler, CallbackContext, ) from agent.tools.text_summary import ConversationSummary SELECT_COMMAND, GET_TEXT = range(2) class LangChainAgentBot(ConversationSummary): 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 async def create_response(self, update: Update, context: CallbackContext) -> None: await update.message.chat.send_action(action=telegram.constants.ChatAction.TYPING) await update.message.reply_text(update.message.text)