Python 3 Flask Whatsapp Web API Example to Build Whatsapp Bot to Send Messages & Files in Browser
170 views
Jun 3, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
So in this video I will show you how to
0:04
build out a WhatsApp bot which can
0:07
actually automatically send messages for
0:09
you using a flask web application So for
0:15
this we are using this API I have given
0:18
the link in the description of this
0:19
video So first of all you just need to
0:21
create a free account here After
0:24
creating a free account you can login
0:26
with your Google account and then it
0:28
will grant you with 150 messages free
0:31
messages You can try out this free
0:33
API It will give you 150
0:36
messages and uh it will give you your
0:40
token as well I have already created
0:42
this So this will be your token So just
0:46
link with your own I've already linked
0:49
in with my mobile number WhatsApp number
0:52
So you just need to link it and just
0:55
create a simple channel So I am there
0:57
inside this So let me build out a flash
1:02
cap
1:06
So let me just show you the application
1:08
that we will be building here So this
1:10
will be a simple web application which
1:13
will actually contain this two input
1:17
fields where you will write the number
1:19
and actually the message and there is a
1:21
send button out there So it's actually a
1:24
web application as you can see it is
1:25
running on local host and here you will
1:28
input the number of the user to which
1:30
you are sending out the
1:35
message So followed by the message and
1:37
now as I click the send button you will
1:41
basically see it will make the response
1:44
to the API and the response will be
1:46
returned to us Message
1:48
sent And if I show you WhatsApp web you
1:51
will see this message is automatically
1:55
sent to to this phone number As you can
1:58
see it's a WhatsApp
2:00
bot So we input the number we input the
2:03
actual message that needs to be sent So
2:06
again if I repeat
2:08
this and
2:13
uh again if I click send here you will
2:16
see again the message will be sent
2:18
automatically you will see that So it's
2:21
a simple WhatsApp bot kind of a
2:24
application inside flask I will show you
2:26
how to get started here step by step So
2:30
first of all just create a simple
2:31
account here I've already created this
2:35
login with your Google account and it
2:37
will give you this 150 free
2:41
messages So after that you need to
2:44
create a flask
2:46
application So all the source code I
2:49
have given in the description of the
2:54
video So first of all just
2:59
Make a simple app py file and after
3:06
that you need to import the flask from
3:11
that import flask and uh the request
3:16
module and the
3:19
JSON and also render
3:23
template And then we also need the
3:25
request module as well to actually make
3:27
the request to the API And then we'll be
3:30
initializing the new flask app like
3:33
this And then here we need to specify
3:35
the a API token So this API token it
3:39
will be giving So simply copy this from
3:42
here Once you create the account the
3:45
token will be assigned to you So you
3:47
need to use the token After that
3:52
uh we will have this hook here which
3:55
will
3:56
be I have given all this script in the
4:00
description of the video So if you need
4:01
the full
4:02
script the link is given in the
4:05
description you can directly copy paste
4:07
the full overall
4:12
script So inside this web hook we will
4:15
be listening for all the messages which
4:17
will be coming
4:22
So data request
4:28
JSON So this is essentially we are
4:30
listening it's kind of a hook where we
4:34
are listening for any sort of messages
4:37
which will be coming right here inside
4:40
this
4:42
hook So received message So if someone
4:45
sends you a message then this will be
4:48
printed
4:50
out But for this application we just
4:53
need a simple index.html file where we
4:56
allow the user to input the message So
4:59
here we are loading this index.html So
5:03
right in the templates
5:05
folder in the flags we will create this
5:08
index html file And right here we will
5:11
allow the user
5:14
to having a simple
5:17
form where inside the form we will have
5:21
two input fields for entering the phone
5:24
number and actually the actual message
5:28
and we have will be having a button So
5:32
this will be a simple form uh if I try
5:34
to run the application now by going to
5:43
localhost So now it will look something
5:46
like this This is will be a form So when
5:49
you submit the form right here you just
5:51
need to
5:53
write make a simple fetch request a post
5:57
request So write in the JavaScript
6:04
just after the body So right here we are
6:06
making this post request fetch request
6:09
slash
6:10
send It's a post request So we are
6:13
sending this data which is these to and
6:17
body So now we just need to make this
6:20
post
6:21
request inside your Python file
6:28
So so right in this post request inside
6:32
slash send just after
6:35
this we are getting the data that is
6:39
submitted through the form
6:41
here to body everything and then now we
6:44
here we are calling this function which
6:46
is send response So now we just need to
6:50
define this function which is send
6:52
response which will get
6:56
executed which will be responsible for
6:58
sending the WhatsApp message So
7:02
send response and uh to and
7:07
body So right here making a
7:11
simple request to the API
7:14
https
7:26
gate So we will providing the payload
7:30
which will be the two values the two
7:42
And then we also be passing the headers
7:44
which will contain the API
7:47
token and
7:49
then our response will be sent So as
7:53
soon as the response is sent our message
7:55
will also be
8:00
sent like this
8:03
So this completes the application
8:09
So if I just show you the application
8:12
Now if
8:14
I enter a 10digit mobile number then I
8:18
enter my message Click on send Now you
8:21
will see message will be sent And if I
8:23
check now you will
8:25
see your message is successfully sent So
8:30
in this way guys you can build out a
8:31
simple WhatsApp web bot kind of a bot
8:36
which can where you can actually send
8:38
messages automatically using this API
8:42
So first of all you need to create an
8:45
account here It will give you 150 free
8:48
messages and uh after that you just need
8:51
to subscribe to their API to get more
8:54
messages As you can see I've used up six
8:57
messages out of 150 So when you sign up
9:00
you will get this
9:02
free token free messages as well So
9:06
there is some limitations to it as well
9:08
So you can upgrade the if you want the
9:11
unlimited access So thank you very much
9:14
for watching this video and also check
9:16
out my website freemediatools.com
9:20
uh which contains uh thousands of tools
#Intelligent Personal Assistants
#Programming
#Scripting Languages
#Software
#Text & Instant Messaging
#Voice & Video Chat