Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/asbdaryaee/ollama-telegram-bot

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.
https://github.com/asbdaryaee/ollama-telegram-bot

ollama ollama-api telegram telegram-bot

Last synced: 10 days ago
JSON representation

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.

Awesome Lists containing this project

README

        

# 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](https://core.telegram.org/bots#botfather).
- **Ollama API**: Ensure you have access to the Ollama API and know the endpoint URL.

## Setup

1. Clone the repository:

```bash
git clone https://github.com/AsbDaryaee/telegram-ollama-bot.git
cd telegram-ollama-bot
```

2. Install dependencies:

```bash
npm install
```
OR
```bash
pnpm i
```

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

```env
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:

```bash
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

```plaintext
.
├── 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:

```plaintext
Sorry, I couldn't process your message. Please try again later.
```

- If a non-text message is sent, the bot responds with:

```plaintext
I can only process text messages.
```

## Dependencies

- [node-telegram-bot-api](https://github.com/yagop/node-telegram-bot-api)
- [axios](https://github.com/axios/axios)
- [dotenv](https://github.com/motdotla/dotenv)

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Contributing

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

## Acknowledgments

- [Telegram Bot API](https://core.telegram.org/bots/api)
- [Ollama API](https://ollama.ai)