Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Component Sharing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gagandeep Singh Bhatia
Component Sharing
Commits
28a9c5f2
Commit
28a9c5f2
authored
Apr 10, 2025
by
Sonawane Amol Madhjuar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
2fd19f3a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
Amol/WhatsappChatbot/MessageSender.java
Amol/WhatsappChatbot/MessageSender.java
+34
-0
No files found.
Amol/WhatsappChatbot/MessageSender.java
0 → 100644
View file @
28a9c5f2
package
com
.
bot
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
public
class
MessageSender
{
private
static
final
String
ACCESS_TOKEN
=
"EAFYJZCF8GyacBOZBlxVNRwqZBNA4BJVYYCH9gKRk0fjdG1XaONKXQnDIqldZB8mvpNVpILnCuOsHyv81CBKa3pG9G6pRsEAxTI4FAUdFEBhlmsV22YdBs5svyKmFe4bcsuirk8wvPoTHTXTsCvqDZBLTwgmDSz9NZC9rfUBxSVTM37zZCcHZBZAm69duKjUxO56ZBAeOr4KdBUyJxUHx965TeBYSoKULRcTLXH3HcZD"
;
private
static
final
String
PHONE_NUMBER_ID
=
"647550301772780"
;
public
static
void
sendTextMessage
(
String
to
,
String
messageBody
)
{
try
{
URL
url
=
new
URL
(
"https://graph.facebook.com/v19.0/"
+
PHONE_NUMBER_ID
+
"/messages"
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"POST"
);
conn
.
setRequestProperty
(
"Authorization"
,
"Bearer "
+
ACCESS_TOKEN
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setDoOutput
(
true
);
String
json
=
String
.
format
(
"{\n \"messaging_product\": \"whatsapp\",\n \"to\": \"%s\",\n \"text\": { \"body\": \"%s\" }\n}"
,
to
,
messageBody
);
OutputStream
os
=
conn
.
getOutputStream
();
os
.
write
(
json
.
getBytes
());
os
.
flush
();
os
.
close
();
int
code
=
conn
.
getResponseCode
();
System
.
out
.
println
(
"Response Code: "
+
code
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment