scssCopy code
import telegram
import random
import chatgpt
bot = telegram.Bot(token="YOURBOTTOKEN")
model = chatgpt.ChatGPT(apikey="YOURAPI_KEY")
def generate_message(input_text):
output_text = model.generate_text(input_text, length=100)
return output_text
def handle_message(update, context):
text = update.message.text
reply_text = generate_message(text)
update.message.reply_text(reply_text)
def main():
updater = telegram.ext.Updater(token="YOUR_BOT_TOKEN", use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, handle_message))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()