0% found this document useful (0 votes)
29 views2 pages

Telegram Bot Code with OpenAI Integration

The document contains code for a Telegram bot that utilizes OpenAI's GPT model to respond to user messages. It includes a main.py file for bot functionality and an example.py file for running a Flask web server. The bot responds to commands and messages, providing helpful assistance based on user input.

Uploaded by

lmcet Principal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Telegram Bot Code with OpenAI Integration

The document contains code for a Telegram bot that utilizes OpenAI's GPT model to respond to user messages. It includes a main.py file for bot functionality and an example.py file for running a Flask web server. The bot responds to commands and messages, providing helpful assistance based on user input.

Uploaded by

lmcet Principal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Working Code Telegram Bot

CODE for [Link]:


import os

from boltiotai import openai

import asyncio
from aiogram import Bot, Dispatcher, types
from [Link] import CommandStart

from example import example

bot = Bot(token='Replace this with your actual bot token id')

dp = Dispatcher()

openai.api_key = [Link]['OPENAI_API_KEY']

example()

@[Link](CommandStart(['start', 'help']))
async def welcome(message: [Link]):
await [Link]('Hello! I am GPT Chat BOT. You can ask me anything :)')

@[Link]()
async def gpt(message: [Link]):
messages = [{"role": "system", "content": "You are a helpful assistant."}, {"role":"user",
"content":[Link]}]

response = [Link](model="gpt-3.5-turbo", messages=messages)

await [Link](response['choices'][0]['message']['content'])

async def main():


await dp.start_polling(bot)

if __name__ == "__main__":
[Link](main())
CODE for [Link]:
from flask import Flask, render_template
from threading import Thread
app = Flask(__name__)
@[Link]('/')
def index():
return "example"
def run():
[Link](host='[Link]',port=8080)
def example():
t = Thread(target=run)
[Link]()

You might also like