Forum in maintenance, we will back soon 🙂
Python Telegram bot
Hello, so I recentyl got my hands on a telegram chatbot python script that connects chtagpt api to the telegram interface. Though I am not able to fully custmoise it. For instance I've created a english teaching bot but I want to add a timer to start when the session starts and and notify when the session ends and and want a second prompt after the session that tells to like this is your score or something and analysis of the conversation. Also I want to add a limit of texts a person can send like for a demo reason. I really hope you can help me out in making this project. Thanks Hassan!
Use the following prompt in GPT-4:
You are an expert in the Python programming language and I am going to be asking you questions about the best way to program a problem. You will answer in a step by step way to ensure the accuracy of your answer. I don't want to see the steps but the final answer after you have verified yourself on the possible answers. Also I would like a list of references that support your answer following the answer. Okay?
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
can you share your script workflow here. or attach the script
Sure, here's the script. I recently learned about telegram web app. Thinking if that would be a better approach to get my end product.
P.s: Is it possible to talk via email? Thanks!
from telegram.ext import Updater, MessageHandler, Filters
import telegram
import openai
from moviepy.editor import AudioFileClip
import time
openai.api_key = ""
TELEGRAM_API_TOKEN = ""
messages = [{"role": "assistant", "content": "Act as Emily, a friendly English teacher, you are a spoken english teacher"}]
def text_message(update, context):
messages.append({"role": "user", "content": update.message.text})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
ChatGPT_reply = response["choices"][0]["message"]["content"]
update.message.reply_text(text=f"*[Bot]:* {ChatGPT_reply}", parse_mode=telegram.ParseMode.MARKDOWN)
messages.append({"role": "assistant", "content": ChatGPT_reply})
def start_timer(duration):
if "for" in duration:
# Extract the duration from the phrase
duration = int(duration.split(" ")[4].split("-")[0])
# Start the timer
print(f"Starting the timer for {duration} minutes.")
time.sleep(duration * 60)
print("Timer is up!")
updater = Updater(TELEGRAM_API_TOKEN, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(MessageHandler(Filters.text & (~Filters.command), text_message))
dispatcher.add_handler(MessageHandler(Filters.voice, voice_message))
updater.start_polling()
updater.idle()
@faizan How do you plan to use this; locally or deployed on a server?
Maybe check out framework libraries like Flask, FastAPI or Streamlit to help you.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@ssadvisor Thanks you for your reply sir. I am currently deploying it using Pythonanywhere. But the functionality is limited to me making requests and getting answers, just like chatgpt on telegram. But I wish to make it fully function for my project . I mean it would be possible if I took a separate web app approach, but using telegram, I am not too sure. I really want to make this project a reality!
@faizan I have a couple of suggestions:
1) Get it working locally before deploying it to Pythonanywere.
2) Create a project under your account on github for it so you can get other eyes on it easily.
Once you have the application working you can deploy it.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@ssadvisor Noted sir. I'll get to github. Though coming from a no-coding background I would require assitance.
@faizan YouTube is your friend for tutorials. Plus github has been around for decades and the documentation is plentiful. Coding is nothing more than creating a map for your data and then telling the data what to do at each stop along the way.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack