Contents

My First OpenAI (ChatGPT) Powered Telegram Bot!

AI.jpg

TLDR

I have developed and deployed a Telegram Bot that is powered with OpenAI capabilities to help administrate the SCS Cyber Community Supergroup. This post is just to announce the launch of this Telegram Bot, and breifly share about the background, this bot’s features and the AI models it uses. To learn more about how to deploy it securely, you can visit my GitHub repository .

This Telegram Bot was trained with closed to approximately 1000 data points using the GPT 3.0 Ada as our base model. It would classify message into any of the following five classes: news, jobs, articles, trainings, others . This model will then be used to aid moving messages according to their classifications to the right Topics. If you are a user and like this GitHub project , please feel free to mark it with a ⭐ !


Coming soon in my next posts, I will share insights about this project. What are the considerations and challenges in developing an AI system that is designed for real-world application? Is secure coding and deployment actually possible? Is cybersecurity really that expensive? Stay tuned!


Background

As part of the SCS Cyber Chapter’s Cyber Mentoring Programme, a Telegram Supergroup was set up to enable our cyber community to provide continuous support to the one another. In this Supergroup, we share problems and suggestions. We have active discussions ranging from cyber discussions (e.g. SaaS, OT security, AI, ZTA, PQC, etc.) to seeking for cyber career advices. This community has also actively shared various online training resources and recommended books to job postings from various companies. You can join this group via the link here .


However, as this Supergroup grows, it started to become messy where members started to have discussions in the wrong groups. 😞 This started to become an administrative nighmare for me and my fellow administrator, Hui Yi, where we have to manually move the messages around.

/openai-powered-telegram-bot/Nightmare.jpg


Even though it was tedious, it was easy for us as a human being to sense make messages and make a judgement. However, as the messages are not predefined, it is not an easy job for a software to make a judgement!


💡 OpenAI’s popularity struck me! I wondered if OpenAI could help me to classify these messages accurately so that I can move these “wrong” conversations posted to the correct forum topics. Hence, I had explored and leveraged on OpenAI’s natural language processing capability to classify contents - primarily using a finetuned model.


Note
This Telegram Bot project is my personal project and initiative as a member of the cyber community. Any vulnerabilities identified would be directly attributed to my work, and I will be glad to fix any reported vulnerabilites soonest. If you find any vulnerabilities, please refer to the Security section.


Features and its AI Models

As this project is developed to support the cybersecurity community, it is designed with security in mind with the intention to promulgate more defensive coding and deployment practices among the development community.

This is a simple Telegram Bot that is equipped with OpenAI capabilities to help administrate the Supergroup. It was trained with closed to approximately 1000 data points using the GPT 3.0 Ada as our base model. It would classify message into any of the following five classes: news, jobs, articles, trainings, others. The collection of the past messages was done using another script using Telethon library and is not within the scope of this project.


As the dataset at present is not uniformly distributed and generally small, the model will be retrained at a later date as the chatgroup receives more messages which can be used as an input to train the model. For the free text natural language interaction feature, it leverages GPT 3.5 Turbo .


It is currently built with the following functions:

  • Permit only Administrators (including the mentors and the owner) to send messages in the General topic that is reserved for mass communication.
  • Permit only Adminstrators to interact with ChatGPT using the /gpt command, e.g. /gpt tell me more about Singapore
  • Keep Job Postings topic free from career related discussion. Any discussion found within will be forwarded to Career Discussions topic.
  • Keep Training Resources topic free from cyber discussions. Any discussion found within will be forwarded to Cyber Discussions topic.
  • Keep Cyber News topic to accept only news and articles, but free from cyber discussions. Any discussion found within will be forwarded to Cyber Discussions topic.
  • Keep Reports and Articles topic to accept only reports and articles, and free from cyber news and discussions. News and discussions will be forwarded to Cyber News and Cyber Discussions topics respectively.

Many online examples share how to code and deploy using either Polling or Web Hook modes, but not both within the same application. This project will share how to develop a Telegram Bot that can support both modes within a single application. This is because Polling mode can be useful for quick unit testing and troubleshooting during development and debugging, while Web Hook mode can be useful for production cloud deployments.


Simply by how the application is run, it will operate in either Polling or WebHook mode without having to change any code or configurations. This could mitigate against errorneous deployment of code or configurations in the production environment that uses Web Hook.


In addition, I was having hard time finding out how to process messages for Supergroup as I have not found examples that share about how to process messages for Supergroup. Hopefully this project can be useful to those who are looking for this answer. If you do reference this project on how to process messages for Supergroup, I would greatly appreciate if you could credit this project. 😉



Security

Important Note

If you believe you have found a security vulnerability in any of my repositories, please report it to me. I will be more happy to fix it with your help.


Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests. Instead, please send an email to opensource.report.vulnerability@gmail.com


Please include as much of the information listed below as you can to help us better understand and resolve the issue:

  • The type of issue (e.g., IDOR, SQL injection, or cross-site scripting)
  • Full paths of source file(s) related to the manifestation of the issue
  • The location of the affected source code (tag/branch/commit or direct URL)
  • Any special configurations or pre-requisites that are required to reproduce the issue
  • Step-by-step instructions to reproduce the issue
  • Proof-of-concept or exploit code. It will be great if it is available. :)
  • Impact of the issue, including how an attacker might exploit the issue

This information will help me to triage your report more quickly.



Personal Reflection

I am happy that I have taken on actions to work on this project during my personal time, and it has finally bear fruits. This bot has worked well so far for me, and it is also probably because AI was applied to solve relevant problems.


Through working on this project, I have taken one more step closer to understand our application developer counter parts so that I can engage with them more relevantly through gaining experience in deployment of products for real-world applications.


That said, life isn’t a breeze. There are multiple insights and challenges that came along the way which I will share more in the upcoming posts.


Special thanks to my wife and son for giving me time to work on this project.


If you like this post, please share it to reach a wider LinkedIn community.