Telegram Oracle v0.1.0

Overview

Our Telegram integration allows customers to interact with our AI model using the popular Telegram messaging platform. This integration enables users to ask questions, provide feedback, and receive responses directly within the Telegram app.

Features

  • Conversational Interface: Users can interact with our AI model using natural language, asking questions and receiving responses in a conversational format.

  • MarkdownV2 Support: Our integration supports MarkdownV2 formatting, allowing users to receive richly formatted responses with bold, italic, and other text styles.

  • Error Handling: Our integration includes robust error handling, ensuring that users receive a response even if there's an issue with the API request or response.

  • Fallback to Plain Text: If MarkdownV2 parsing fails, our integration falls back to sending a plain text response, ensuring that users always receive a response.

How it Works

  1. Users interact with our Telegram bot by sending a message or question.

  2. Our integration sends the user's input to our AI model for processing.

  3. Our AI model responds with a JSON object containing the response text.

  4. Our integration parses the response text as MarkdownV2 and sends it to the user as a Telegram message.

  5. If MarkdownV2 parsing fails, our integration falls back to sending a plain text response.

Usage Examples

To trigger our Telegram integration, users can send a message to our bot with the following format:

Hey fana or Fanabot or Ok fana followed by <question or message>

For example:

Hey fana or Fanabot or Ok fana followed by What is the weather like today?

This will send a request to our AI model, which will respond with a JSON object containing the response text. Our integration will then parse the response text as MarkdownV2 and send it to the user as a Telegram message.

Code Snippets

Here's an example of how to use our Telegram integration in a Telegram group:

    // Log form contents before sending
    debug!("Sending request to API: {}", api_url);
    debug!("Sending form to API. Text content: '{}'", cleaned_text);

    let response_text = match send_api_request(api_url, api_token, create_form).await {
        Ok(text) => {
            debug!("Received response from API: {}", text);
            text
        }
        Err(e) => {
            error!("Error sending API request: {}", e);
            "Ouch, something went wrong, please try again in a few minutes".to_string()
        }
    };

    let message_text = match parse_api_response(&response_text) {
        Ok(text) => text,
        Err(err) => {
            error!("Error parsing API response: {}", err);
            return Err("Error parsing API response".into());
        }
    };
    debug!("Parsed API response: {}", message_text);

    // Update state with new messages
    let mut state_guard = state.lock().await;
    let chat_state = state_guard.get_or_create_chat_state(&chat_id);
    chat_state.update_messages(
        username.clone(),
        cleaned_text.clone(),
        Some(message_text.clone()),
    );
    debug!("Updated state with new messages");

This code snippet uses the node-telegram-bot-api library to create a Telegram bot instance, and listens for messages starting with the /botname command. When a message is received, it sends a request to our AI model with the user's question, and then parses the response text as MarkdownV2 before sending it back to the user.

Benefits

  • Convenient: Users can interact with our AI model directly within the Telegram app, without needing to switch to a separate interface.

  • Flexible: Our integration supports a wide range of use cases, from simple Q&A to more complex conversations.

  • Robust: Our error handling and fallback mechanisms ensure that users always receive a response, even if there's an issue with the API request or response.

Last updated