Skip to content

This repository contains the code for a simple Telegram bot that integrates with the Ollama API to process user inputs and provide intelligent responses. The bot is built using the node-telegram-bot-api library and uses axios for HTTP requests.

License

Notifications You must be signed in to change notification settings

AsbDaryaee/Ollama-Telegram-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot Integrated with Ollama API

This repository contains the code for a simple Telegram bot that integrates with the Ollama API to process user inputs and provide intelligent responses. The bot is built using the node-telegram-bot-api library and uses axios for HTTP requests.

Features

  • Accepts user input via Telegram chat.
  • Sends user input to the Ollama API for processing.
  • Returns responses generated by the Ollama API to the Telegram chat.
  • Handles basic commands such as /start and /stop.

Prerequisites

  • Node.js: Ensure you have Node.js installed on your system.
  • Telegram Bot Token: Obtain a bot token by creating a bot using BotFather.
  • Ollama API: Ensure you have access to the Ollama API and know the endpoint URL.

Setup

  1. Clone the repository:

    git clone https://github.com/AsbDaryaee/telegram-ollama-bot.git
    cd telegram-ollama-bot
  2. Install dependencies:

    npm install

    OR

    pnpm i
  3. Create a .env file in the root directory and add the following environment variables:

    TELEGRAM_TOKEN=your-telegram-bot-token
    OLLAMA_API_URL=http://localhost:11434/api/generate  # Replace with your Ollama API endpoint
    PROXY=http://your-proxy-url  # Optional, if you need a proxy
  4. Run the bot:

    node server.js

    The bot will start polling Telegram for messages.

Usage

Starting The Bot Looks Like This.

  1. Start the bot by sending the /start command in the Telegram chat.
  2. Send your questions or prompts to the bot.
  3. The bot processes your input using the Ollama API and replies with the generated response.

Project Structure

.
├── index.js       # Main script for the bot
├── package.json   # Project dependencies and metadata
├── .env           # Environment variables (not included in the repository)

Example Interaction

User: /start
Bot: Welcome, Send Your First Question or Prompt!

User: What is the capital of France?
Bot: The capital of France is Paris.

Error Handling

  • If the bot encounters an issue communicating with the Ollama API, it sends the following message to the user:

    Sorry, I couldn't process your message. Please try again later.
    
  • If a non-text message is sent, the bot responds with:

    I can only process text messages.
    

Dependencies

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Acknowledgments

About

This repository contains the code for a simple Telegram bot that integrates with the Ollama API to process user inputs and provide intelligent responses. The bot is built using the node-telegram-bot-api library and uses axios for HTTP requests.

Topics

Resources

License

Stars

Watchers

Forks