Professional Documents
Culture Documents
Python
Python
Python
Bachelor of Technology
in
Computer Science and Engineering
by
Prisha Mohan (2000970100079)
Rohit Saini (2000970100086)
Sagar Malik (2000970100089)
CERTIFICATE
This is to certify that the project report entitled “Telegram Bot” submitted by Ms. Prisha Mohan
(2000970100079), Mr. Rohit Saini (2000970100086), Mr. Sagar Malik (2000970100089) to the Galgotias
College of Engineering & Technology, Greater Noida, Utter Pradesh, affiliated to Dr. A.P.J. Abdul Kalam
Technical University Lucknow, Uttar Pradesh in partial fulfillment of Degree of Bachelor of
Technology in Computer science & Engineering is a bonafide record of the Project Based Learning Report
carried out by them under my supervision during the even semester 2021-2022.
ACKNOWLEDGEMENT
We have taken efforts in this project. However, it would not have been possible
without the kind support and help of many individuals and organizations. We
would like to extend my sincere thanks to all of them.
We are highly indebted to Mr. Dinesh Babu M for his guidance and constant
supervision. Also, we are highly thankful to them for providing necessary
information regarding the project & also for their support in completing the
project.
We also express gratitude towards our parents for their kind co-operation and
encouragement which helped me in completion of this project. Our thanks and
appreciations also go to our friends in developing the project and all the people
who have willingly helped me out with their abilities.
(Prisha Mohan)
(Rohit Saini)
(Sagar Malik)
ABSTRACT
The project aims to develop a Telegram Bot, using Python. Python is an all-round valuable
programming language used in Dialog flow. It is used for the most prominent programming in
light of its versatility, straightforwardness and longstanding reputation. Python is significant
for developers as it shows their programming abilities amongst the prospective employers.
This project will be a best guide to polish your python skills and gain expertise in it. With the
help of this project, the user will be able to easily access different python material for practice
as well as study, all summarized in one place.Telegram is an evolving platform that is famous
for its security, message delivery speed, and lots of development perks that make
communication enjoyable. In recent times Telegram has become one of the most used
messaging and content sharing platforms, it has no file sharing limit like Whatsapp and it
comes with some preinstalled bots one can use in any channels (groups in case of whatsapp)
to control the behavior or filter the spam messages sent by users. Telegram Bot draws its
inspiration from so many existing bots that are available 24/7 and can deliver lots of helpful
information in a blink of an eye. This bot is a helping hand to those who are not already
oriented and need a helping hand. Chatbots are revolutionizing the way people interact with
technology. In recent years, their simplicity and low cost have helped drive adoption across
various fields and industries.
INDEX
CONTENTS
TITLE PAGE
Certificate i
Acknowlwdgement ii
Abstract iii
Contents iv
1.INTRODUCTION
INTRODUCTION
PURPOSE
EXISTING SYSTEM
PROPOSED SYSTEM
2.SYSTEM ANALYSIS
CREATING A BOT
WORKING OF BOT
SECURE
SETTING UP
3.FEASIBILITY STUDY
POPULARITY
APPLICATIONS
EXAMPLES IN INDUSTRY
4.REQUIREMENTS SPECIFICATIONS
SYSTEM REQUIREMENTS
BASIC REQUIREMENTS
TOOLS NEEDED
USER SKILLS
PLATFORM USED
5.SYSTEM DESIGN
DFD DIAGRAMS
UML DIAGRAMS
6.OUTPUT SCREENS
SCREENSHOTS
7.SYSTEM TESTING
8.CONCLUSION
9.FUTURE SCOPE
CHAPTER 1
INTRODUCTION
INTRODUCTION
Chatbots are often touted as a revolution in the way users interact with technology and
businesses. They have a fairly simple interface compared with traditional apps, as they only
require users to chat, and the chatbots are supposed to understand and do whatever the user
demands from them, at least in theory. Chatbots are all the rage at the moment, with some
predicting that they will be bigger than mobile apps. The main idea of chatbots is that
instead of having to dig through awkward mobile menus and learn UIs, you'll simply have
a conversation with a bot through a familiar
instant messaging interface. If you want to order a Pizza, you start a conversation with
the Domino's Pizza bot and have the same conversation with it that you might have with a
human.
You can devise a chatbot that will help your customers when they ask certain questions
about your product, or you can make a personal assistant chatbot that can handle basic tasks
and remind you when it’s time to head to a meeting or the gym.
There are a few different platforms that allow you to build your own chatbot. One of these,
which is arguably the simplest to use and is also growing steadily in popularity,
is Telegram.
Telegram is one of the more popular IM platforms today, as it allows you to store messages
on the cloud instead of just your device and it boasts good multi-platform support, as you can
have Telegram on Android, iOS, Windows, and just about any other platform that can
support the web version. Building a chatbot on Telegram is fairly simple and requires few
steps that take very little time to complete. The chatbot can be integrated in Telegram groups
and channels, and it also works on its own.
PURPOSE
Bots are simply accounts operated by software – not people – and they'll often have AI
features. They can do anything – teach, play, search, broadcast, remind, connect, integrate
with other services, or even pass commands to the Internet of Things. Telegram Bots are
special accounts that do not require an additional phone number to set up. Bots are
everywhere. It seems that only yesterday we did not even know about their existence; now
we can barely imagine our life without them. They’ve become widely popular among
numerous active users of messengers since they have various scopes of use – from
entertaining content including step-by-step games and collecting bonus points in restaurants,
to keeping a diet plan, tracking deliveries, and even making payments for different services.
A Telegram Bot is a program that behaves like a normal chat partner with additional
functions. It performs predefined tasks independently and without the user’s involvement.
Many industries are shifting their customer service to chatbot systems. That’s because of the
huge drop in the cost compared to actual humans, and also because of the robustness and
constant availability. Chatbots deliver a degree of user support without substantial additional
cost. Today, chatbots are used in many scenarios, ranging from menial tasks such as
displaying time and weather data to more complex operations such as rudimentary medical
diagnosis and customer communication/support.
EXISTING SYSTEM
- Teach
- Play
- Search
- Broadcast
- Remind
- Connect
- Message
- Emoticons
- Commands
- Inline requests
PROPOSED SYSTEM
FEATURES
A generic and predefined text response
A context using data that the user provides
A specific action (the chatbot interacts with one or more applications)
Reducing costs of personnel that provided customer service
Immediate support and responses for users
Better user experience
Possibility of learning about preferences of the user when using artificial intelligence
systems
Ease of integration in different digital platforms, without the need to download
applications or additional programs.
The word or statement that we have written in the bot gives us the desired Youtube,
geeksforgeeks etc link related to it.
CHAPTER 2
SYSTEM ANALYSIS
Creating a Telegram Bot
JavaScript (node.js)
Java / Kotlin
PHP
C#
Python
Swift
Ruby
When choosing a programming language for bot development, different points come
into play: How “well” do they or their team know the respective programming
language? Which programming tools are available or which libraries can be
accessed?
With the OPC Router communication platform, a Telegram Bot can be created with
just a few clicks without complex programming. With the OPC Router Telegram
Bot Plug-in, the bot is realised through simple graphical configuration. Messages
from other Plug-ins (SAP, OPC, MQTT, etc.) can be easily sent to the bot and are
then sent to the registered chat users. The creation of commands is possible via the
simple creation of triggers in an OPC Router project. In this way, you can create a
Telegram Bot for your own system in just a few minutes.
Setting up
Nearly everything we do will be achievable using only the standard Python libraries, but
we'll also be using the third-party requests module which provides a number of
improvements to Python's urllib, and allows us to make HTTP requests very simply and
concisely. Install this through pip using a command similar to the following (you may need
to use pip instead of pip3 and/or add the --user flag, based on how you usually install
Python libraries).
If you usually use a virtual environment for new Python projects, then set one of those up
first, and install requests inside that.
CHAPTER 3
FEASIBILITY STUDY
Why are they so popular?
Well, the bot simply cannot have colorful design. But beyond any doubts, in comparison to
numerous apps with different design when you have to remember where and what to tap, bot
is more universal and easy; it offers a simple communication via texts.
You do not have to install hundreds of apps for each service if you can receive all necessary
assistance from a bot. This is particularly useful for restaurants and shops. Clients are rarely
eager to install apps from a bunch of places they’ve visited. Due to this, business owners
miss clients’ feedback and lose communication with them. If each of these places had their
own bot available in different messengers, it would be more convenient and friendly to users.
Nobody likes to fill up the storage of their phones with unnecessary apps that will be used
once or twice. However, clients need to engage with the service owners and they will
appreciate doing this through their favorite messenger.
Using a bot, user passes authorization only once when the bot is added to the chat. Client can
use the bot as much as it is necessary, and when there is no need in it anymore, user just
blocks the bot. That’s all, easy! No password resets anymore. No need to remember
passwords or logins used. Adding bot to the site or app increases the number of the user
audience as it makes communication with clients and providing them with the assistance
much easier and user-friendly.
APPLICATIONS
Tutoring
Increasing student engagement
Efficient teaching assistants
Assisting students
Student support
Providing institutional information
Helping with holiday homework
Assessments
Telegram Application
Basic Requirements
A Telegram Account: If you don’t have the Telegram app installed just download it
from the play store. After downloading create an account using your mobile number just
like WhatsApp.
.python-telegram-bot module: Here we will need a module called python-telegram-
bot, This library provides a pure Python interface for the Telegram Bot API. It’s
compatible with Python versions 3.6.8+. In addition to the pure API implementation,
this library features a number of high-level classes to make the development of bots
easy and straightforward. These classes are contained in the “telegram.ext” submodule.
For more information, you can check their official GitHub repo.
Tools Needed
bottle – for our server; a simple and lightweight WSGI micro web-framework
requests – for sending requests to telegram. request lib does not need to be
overrepresented. It is universally used throughout the world in a variety of projects.
Note: you have to install these tools on your computer. We will need them later. For
that, open your bash console and install it via pip
ngrok – this is an app which provides us with public URLs for our interaction with
Telegram WebHook throughout the development phase (look for info on WebHook
below). It is useful, as Telegram will not be able to make a connection with our local
server because we cannot specify our local address in the Telegram API configuration.
You should download ngrok from the official site and put the installed app in the
folder with the project.
User Skills
Some basic Python knowledge to follow this tutorial
You should be able to install Python packages using the pip package manager (or
conda if you're more comfortable with that)
Ideally, you should have written at least a basic SQL statement before, but this is not
strictly necessary (and will only be relevant in Part 2).
All of the code is aimed at Python 3.5, but it should be easily adaptable to other versions of
Python.
PLATFORM USED
INTRODUCTION OF COMPONENTS
Programming Language - PYTHON
Python is an interpreted high-level general-purpose programming language. Python's design
philosophy emphasizes code readability with its notable use of significant indentation. Its
language constructs as well as its object-oriented approach aim to help programmers write
clear, logical code for small and large-scale projects.
Python is dynamically-typed and garbage-collected. It supports multiple programming
paradigms, including structured (particularly, procedural), object-oriented and functional
programming. Python is often described as a "batteries included" language due to its
comprehensive standard library.
Python consistently ranks as one of the most popular programming languages
Why we chose python?
If you want your machine to run on your command like Jarvis did for Tony, yes, it is possible.
It is possible using Python. Python offers a good major library so that we can use it for making
a virtual assistant.
Python is the most used language for AI with multiple libraries and huge support. Apart from
being an open-source programming language, python is also one of the most versatile
programming languages.
Python is free and simple to learn. Its primary features are that it is high-level, dynamically
typed and interpreted. This makes debugging of errors easy and encourages the rapid
development of application prototypes, marking itself as the language to code with.
Features in Python
GUI Programming Support: Graphical User interfaces can be made using a module such
as PyQt5, PyQt4, wxPython, or Tk in python.
Free and Open Source: Python language is freely available at the official website and you
can download it from any given download link with Download Python keyword.
Extensible feature: Python is an Extensible language. We can write us some Python code
into C or C++ language and also we can compile that code in C/C++ language.
Python is Portable language: Python language is also a portable language. For example,
if we have python code for windows and if we want to run this code on other platforms
such as Linux, Unix, and Mac then we do not need to change it, we can run this code on
any platform.
Large Standard Library: Python has a large standard library which provides a rich set of
module and functions so you do not have to write your own code for every single thing.
There are many libraries present in python for such as regular expressions, unit-testing,
web browsers, etc.
In order to install the Python module, we need 'pip', a framework to manage packages
required to install the modules from the trusted public repositories. Once we have 'pip', we
can install the python-telegram-bot module using the command from a Windows command
prompt (CMD) or terminal as shown below:
Syntax:
Once the module is installed, we can verify it by creating an empty Python program file and
writing an import statement as follows:
File: verify.py
1. import telegram
2. Now, save the above file and execute it using the following command in a terminal:
3. Syntax:
4. $ python verify.py
If the above Python program file does not return any error, the module is installed properly.
However, in the case where an exception is raised, try reinstalling the module, and it is also
recommended to refer to the official documentation of the module.
CHAPTER 8
CONCLUSION
The Telegram messenger stands out, compared to competing services such as
WhatsApp and Co, especially because of its special function of bots and channels.
Freely available application programming interfaces (APIs) make life easier if you
want to collect data or automate things. Thus, a Telegram bot is a good way to
deliver information from almost every conceivable area whenever you need it. In
the following article, we would like to discuss exactly this special mode of
operation and show how it can be used in practice.
Once programmed, the Telegram Bot can perform many beneficial tasks.
Programming requires specific knowledge or can be extremely facilitated using
software such as the OPC Router.
A potential use case is temperature data that is stored in an SQL database. If this
data exceeds or falls below a threshold value, the Telegram Bot can immediately
send a message to the responsible person or department. Additionally, this message
allows the user to perform a database query. That provides more precise information
about the temperature problem and prevents a production stop at an early stage.
A Telegram Bot can also share production data. As soon as a production order is
complete, departments involved can receive a message and initiate the next order
from there or inform logistics to start shipping. That helps to avoid downtime and
increase overall plant effectiveness. Due to its intelligent communication, the
Telegram Bot is a valuable addition, especially in industry.
CHAPTER 9
FUTURE SCOPE
We intend to expand our model of python Bot to various other skills which makes one
industry-ready through study and practice, namely by creating another set of bots, namely for
ever-growing technologies such as Artificial Intelligence, Machine Learning, Augmented
Reality, Cloud Computing; and another for learning various programming languages such as
JavaScript, Python, C# etc. We intend to administrate all these bots through a master bot,
which then directs the user towards the bot which helps him/her in learning whatever skills
that he/she wants to.
The most obvious problem with our Bot is that we have to run a Python script manually
every time we want to interact with it. Also, as mentioned before, we always download the
entire message history that Telegram provides. This is both inefficient and unreliable, as
we don't want to unnecessarily download the entire message history if we only want a
single message, and because Telegram only keeps this list of updates for 24 hours. Another
issue is that we pass our message as a string, but because this is converted to a URL before
being sent to Telegram, you'll notice that some unexpected things happen if you send
messages to the bot with special characters (for example, the + symbol will disappear from
all echoed messages). Finally, the Bot throws an index error if we try to run it when there
are no new messages to receive.
Acknowledge each message as it receives it and tells Telegram to not send us that
message again.
Use Long Polling so that we don't have to make too many requests.