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
7bd5b844
Commit
7bd5b844
authored
May 07, 2025
by
Sonawane Amol Madhjuar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
8c9d0a22
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
+117
-0
Amol/A_whatsppBot/WhatsAppComm.java
Amol/A_whatsppBot/WhatsAppComm.java
+117
-0
No files found.
Amol/A_whatsppBot/WhatsAppComm.java
0 → 100644
View file @
7bd5b844
package
ibase
.
communication
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
ibase.utility.BaseLogger
;
import
ibase.utility.UserInfoBean
;
import
ibase.webitm.ejb.DBAccessEJB
;
public
class
WhatsAppComm
{
private
DBAccessEJB
dbAccess
=
null
;
public
String
sendWhatsApp
(
String
actionInfo
,
String
WhatsappXMLString
,
UserInfoBean
userInfo
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
" sendWhatsApp Testing 06-May-25==> "
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
"WhatsappXMLString ==> "
+
WhatsappXMLString
);
BaseLogger
.
log
(
"3"
,
null
,
null
,
" ActionInfo==> "
+
actionInfo
);
try
{
//DBAccessEJB dbAccess = new DBAccessEJB();
String
jsonObject
=
getDBAccess
().
getDBColumnValue
(
"AUTH_APPS_API"
,
"SERVICE_SETTING"
,
(
" APP_ID = '"
+
actionInfo
+
"' "
),
userInfo
.
getTransDB
());
BaseLogger
.
log
(
"3"
,
null
,
null
,
"jsonObject::: ["
+
jsonObject
+
"]"
);
JSONObject
jsonObj
=
new
JSONObject
(
jsonObject
);
String
phoneNumber
=
jsonObj
.
getString
(
"whatsappNumber"
);
String
template_name
=
jsonObj
.
getString
(
"template_name"
);
String
broadcast_name
=
jsonObj
.
getString
(
"broadcast_name"
);
JSONArray
parameters
=
jsonObj
.
getJSONArray
(
"parameters"
);
JSONObject
jsonBodyObj
=
new
JSONObject
();
jsonBodyObj
.
put
(
"template_name"
,
template_name
);
jsonBodyObj
.
put
(
"broadcast_name"
,
broadcast_name
);
jsonBodyObj
.
put
(
"parameters"
,
parameters
);
String
jsonBody
=
jsonBodyObj
.
toString
();
String
channelId
=
"+919673134809"
;
String
accessToken
=
getDBAccess
().
getDBColumnValue
(
"USER_ACC_CHANNEL"
,
"TOKEN_ID"
,
(
" CHANNEL_UUID = '"
+
channelId
+
"' "
),
userInfo
.
getTransDB
());
BaseLogger
.
log
(
"3"
,
null
,
null
,
"accessToken::: ["
+
accessToken
+
"]"
);
String
apiUrl
=
getDBAccess
().
getDBColumnValue
(
"AUTH_APPS_API"
,
"ENDPOINT"
,
(
" APP_ID = '"
+
actionInfo
+
"' "
),
userInfo
.
getTransDB
());
apiUrl
=
apiUrl
+
phoneNumber
;
BaseLogger
.
log
(
"3"
,
null
,
null
,
"ENDPOINT::: ["
+
apiUrl
+
"]"
);
URL
url
=
new
URL
(
apiUrl
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
// Set headers
conn
.
setRequestMethod
(
"POST"
);
conn
.
setRequestProperty
(
"Authorization"
,
"Bearer "
+
accessToken
);
// Replace with your token
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json-patch+json"
);
conn
.
setDoOutput
(
true
);
/*
String jsonBody = "{"
+ "\"template_name\": \"thank_you_for_shop\","
+ "\"broadcast_name\": \"T1\","
+ "\"parameters\": []"
+ "}";
*/
// Write body
try
(
OutputStream
os
=
conn
.
getOutputStream
())
{
byte
[]
input
=
jsonBody
.
getBytes
(
"utf-8"
);
os
.
write
(
input
,
0
,
input
.
length
);
}
// Get response
int
responseCode
=
conn
.
getResponseCode
();
BaseLogger
.
log
(
"3"
,
null
,
null
,
"WhatsApp API Response Code: "
+
responseCode
);
if
(
responseCode
==
200
||
responseCode
==
201
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Message sent successfully via WhatsApp."
);
}
else
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Failed to send WhatsApp message. HTTP code: "
+
responseCode
);
}
conn
.
disconnect
();
}
catch
(
Exception
e
)
{
BaseLogger
.
log
(
"3"
,
null
,
null
,
"Error sending WhatsApp message: "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
return
WhatsappXMLString
;
}
private
DBAccessEJB
getDBAccess
()
{
try
{
if
(
dbAccess
==
null
)
{
dbAccess
=
new
DBAccessEJB
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
dbAccess
;
}
}
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