Friday, March 24, 2023
No Result
View All Result
Get the latest A.I News on A.I. Pulses
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing
No Result
View All Result
Get the latest A.I News on A.I. Pulses
No Result
View All Result

Construct an automatic, AI-Powered Telegram Chatbot with ChatGPT utilizing Flask

January 22, 2023
147 3
Home Natural Language Processing
Share on FacebookShare on Twitter


This weblog describes how one can combine Telegram and create a python software primarily based on the Flask internet framework that may obtain person Telegram messages and make the most of ChatGPT to answer these messages intimately.

Step 1: Create Telegram Bot

To be able to automate the messages with ChatGPT, we simply must create the Telegram Bot. Please observe the directions in our weblog submit Telegram Bot setup from step 1 to step 11. Please verify that you just adopted the weblog’s directions earlier than continuing.

Step 2: ChatGPT API

Please check out our weblog submit, WhatsApp Chatbot With ChatGPT Step 2 “ChatGPT API” which has directions for establishing and utilizing ChatGPT.

Step 3: Combine ChatGPT API with Flask Software

After our ChatGPT API obtained put in efficiently, it’s time to combine it with the flask software. 

Nevertheless, the ChatGPT API will proceed to run within the Firefox browser’s background, which may intrude with receiving responses from the ChatGPT API, subsequently we should finish the method that’s at the moment working the browser.

def course of():
attempt:

# iterating via every occasion of the method
for line in os.popen(“ps ax | grep firefox | grep -v grep”):
fields = line.cut up()

# extracting Course of ID from the output
pid = fields[0]

# terminating course of
os.kill(int(pid), sign.SIGKILL)
print(“Course of Efficiently terminated”)

besides:
print(“Error Encountered whereas working script”)

The flask software we developed in step 1 needs to be modified now. To obtain ChatGPT’s response to person messages, change the prevailing code in your Flask app with the next code.

import requests
import os, sign

from flask import Flask
from flask import request
from flask import Response
from chatgpt_wrapper import ChatGPT

TOKEN = “<Your BOT TOKEN>”

app = Flask(__name__)

def parse_message(message):
print(“message–>”,message)
chat_id = message[‘message’][‘chat’][‘id’]
txt = message[‘message’][‘text’]
print(“Textual content :”, txt)
return chat_id,txt

def tel_send_message(chat_id, textual content):
url = f’
payload = {
‘chat_id’: chat_id,
‘textual content’: textual content
}

response = requests.submit(url,json=payload)
return response

@app.route(‘/’, strategies=[‘GET’, ‘POST’])
def index():
if request.technique == ‘POST’:
msg = request.get_json()

chat_id,txt = parse_message(msg)

bot = ChatGPT()
response = bot.ask(txt)
print(“ChatGPT response: “,response)
tel_send_message(chat_id,response)
course of()
return Response(‘okay’, standing=200)
else:
return “<h1>Welcome!</h1>”

if __name__ == ‘__main__’:
app.run(debug=True)

Notice:

Run the flask software within the terminal: python SCRIPT_NAME.pyRun the ngrok on terminal: ngrok http 5000

Step 4: Check Telegram Chatbot

Please ship some messages to the Telegram bot to obtain the ChatGPT-generated response. Additionally, you will get a response on a server.

Right here is the ChatGPT response on our server.

We are going to get the beneath response within the Telegram Bot.

Do tell us for those who face any points in establishing or utilizing the script. We’d be joyful to assist! Contact us or submit your question within the feedback.

Additionally, take a look at our different tutorials to learn to construct a ChatGPT chatbot on completely different platforms.

WhatsApp with ChatGPT: Construct An Automated, AI-Powered WhatsApp Chatbot With ChatGPT Utilizing Flask

Fb Messenger with ChatGPT: Construct An Automated, AI-Powered Fb Messenger Chatbot With ChatGPT Utilizing Flask

Slack Chatbot with ChatGPT: Construct An Automated, AI-Powered Slack Chatbot With ChatGPT Utilizing Flask

We now have already created a weblog submit collection the place we now have offered a tutorial on methods to create a chatbot for various platforms. You possibly can discover these blogs and be taught how one can set completely different sorts of wealthy responses which might improve person engagement in your chatbot.

Telegram: Create Telegram Bot Utilizing Python Tutorial With Examples

Fb Messanger: Create Fb Messenger Bot Utilizing Python Tutorial With Examples

Slack: Create Slack Bot Utilizing Python Tutorial With Examples

Discord: Create Discord Bot Utilizing Python Tutorial With Examples



Source link

Tags: AIPoweredautomatedBuildChatbotChatGPTFlaskTelegram
Next Post

Construct an automatic, AI-Powered Fb Messenger Chatbot with ChatGPT utilizing Flask

Yr finish abstract: Prime Robocar tales of 2022

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent News

Optimize Knowledge Warehouse Storage with Views and Tables | by Madison Schott | Mar, 2023

March 24, 2023

Bard Makes use of Gmail Information | Is AI Coaching With Private Information Moral?

March 24, 2023

Key Methods to Develop AI Software program Value-Successfully

March 24, 2023

Visible language maps for robotic navigation – Google AI Weblog

March 24, 2023

Unlock Your Potential with This FREE DevOps Crash Course

March 24, 2023

High 15 YouTube Channels to Degree Up Your Machine Studying Expertise

March 23, 2023

Categories

  • A.I News
  • A.I. Startups
  • Computer Vision
  • Data science
  • Machine learning
  • Natural Language Processing
  • Robotics
A.I. Pulses

Get The Latest A.I. News on A.I.Pulses.com.
Machine learning, Computer Vision, A.I. Startups, Robotics News and more.

Categories

  • A.I News
  • A.I. Startups
  • Computer Vision
  • Data science
  • Machine learning
  • Natural Language Processing
  • Robotics
No Result
View All Result

Recent News

  • Optimize Knowledge Warehouse Storage with Views and Tables | by Madison Schott | Mar, 2023
  • Bard Makes use of Gmail Information | Is AI Coaching With Private Information Moral?
  • Key Methods to Develop AI Software program Value-Successfully
  • Home
  • DMCA
  • Disclaimer
  • Cookie Privacy Policy
  • Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2022 A.I. Pulses.
A.I. Pulses is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing

Copyright © 2022 A.I. Pulses.
A.I. Pulses is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In