Coder Social home page Coder Social logo

telegram-bot-python's Introduction

Telegram chat-bot

Hi everyone, this is repository for my personal demo project on connecting Telegram and OpenAI to provide answers to all the users questions using OpenAI GPT-3. This is written in Python and served with Flask. This bot can only handle:

  • text messgaes
  • it has a built-in menu options as well

You can interact with this bot here.

GitHub User's stars GitHub followers

Youtube

I have recorded a quick video on the setup of this chat-bot, in case you want to replicate the work, you can watch it here.

What you will need

There are couple of things that you need before you get started following this repository.

  • OpenAI API key, since it is open to all, you can create an account here and access the key.
  • You need a telegram bot API key as well, you can get it with interacting with Botfather on Telegeram here. Alternatively, you can one of my video on how to create a Telegram bor here.
  • Mongodb Atlas account for saving all the messages to mongodb.
  • API requesting application like Postman, Insomnia, etc.
  • NGROK for local testing.

How to use it

To replicate the work of this repository and run it locally, you need to follow these steps:

  • create a .env file inside the root directory, create these environmental variables:
    TOKEN=YOUR TELEGRAM BOT API KEY
    HEADER_TOKEN=A RANDOM STRING FOR SECURITY
    OPENAI_API_KEY=OPENAI API KEY
    ME=YOUR TELEGRAM ID
    CONNECTION_STRING=mongodb+srv://USERNAME:[email protected]
    DB_NAME=MONGODB DB NAME
    COLLECTION_NAME=MONGO DB COLLECTION NAME
    
  • create a virtual environment and activate it before installing the packages
  • install all the required dependencies from the requirements.txt file
pip install -r requirements.txt
  • run the server with either of the following commands
python run.py
gunicorn run:app
  • start NGROK engine on the same port as the python application is running.
  • set the webhook by sendin a POST request on the following url
http://localhost:5000/set-telegram-webhook

pass the following body with the request in raw json format

{
    "url": "YOUR NGRK URL/telegram",
    "secret_token": "HEADER_TOKEN DEFINED IN THE .env FILE"
}
  • in case you want to set menu for the Telegram bot, you can send a POST request on the following url
http://localhost:5000/set-telegram-menu-commands

pass the following body with the request in raw json format

{
	"commands": [
		{
			"command": "/contactme",
			"description": "Contact me"
		},
		{
			"command": "/youtube",
			"description": "My youtube"
		}
	]
}

About me

I am Raj Kapadia, I am passionate about AI/ML/DL and their use in different domains, I also love to build chatbots using Google Dialogflow ES/CX, I have backend development experience with Python[Flask], and NodeJS[Express] For any work, you can reach out to me at...

telegram-bot-python's People

Contributors

rajkkapadia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.