Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
whatsappweb
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mauro Paolo Josue Zuñiga Mallqui
whatsappweb
Commits
0dcde996
Commit
0dcde996
authored
Oct 17, 2025
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] AVANCE
parent
234713b1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
11 deletions
+36
-11
pom.xml
pom.xml
+5
-1
WhatsappRest.java
src/main/java/sacooliveros/whatsappweb/api/WhatsappRest.java
+23
-6
WhatsappBean.java
...main/java/sacooliveros/whatsappweb/bean/WhatsappBean.java
+8
-4
No files found.
pom.xml
View file @
0dcde996
...
...
@@ -62,7 +62,11 @@
<version>
1.18.32
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
</dependencies>
<build>
<finalName>
whatsappweb
</finalName>
...
...
src/main/java/sacooliveros/whatsappweb/api/WhatsappRest.java
View file @
0dcde996
...
...
@@ -4,6 +4,7 @@ import java.util.Map;
import
java.util.logging.Logger
;
import
org.apache.catalina.connector.Response
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
...
...
@@ -25,14 +26,11 @@ public class WhatsappRest {
Logger
logger
=
Logger
.
getLogger
(
WhatsappRest
.
class
.
getName
());
@Autowired
WhatsappBean
whatsappBean
;
@Autowired
WhatsappService
whatsappService
;
public
WhatsappRest
(
WhatsappBean
whatsappBean
,
WhatsappService
whatsappService
)
{
this
.
whatsappBean
=
whatsappBean
;
this
.
whatsappService
=
whatsappService
;
}
@GetMapping
(
"qr"
)
public
ResponseEntity
<?>
getQR
()
{
Whatsapp
whatsapp
=
whatsappBean
.
getWhatsapp
();
...
...
@@ -44,7 +42,7 @@ public class WhatsappRest {
if
(
whatsapp
.
isConnected
())
{
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
"Already connected"
);
}
else
{
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
utils
.
generateQR
()
);
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
"Connecting..."
);
}
}
...
...
@@ -59,6 +57,7 @@ public class WhatsappRest {
if
(
whatsapp
.
isConnected
()){
whatsapp
.
disconnect
().
join
();
whatsapp
.
logout
().
join
();
whatsappBean
.
setWhatsapp
(
null
);
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
new
JSONObject
().
put
(
"message"
,
"Logout has been done correctly, wait some minutes untill it actually logs out"
).
put
(
"status"
,
false
).
toMap
());
}
else
{
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
new
JSONObject
().
put
(
"message"
,
"Not connected."
).
put
(
"status"
,
false
).
toMap
());
...
...
@@ -70,6 +69,24 @@ public class WhatsappRest {
}
}
@GetMapping
(
"status"
)
public
ResponseEntity
<?>
status
()
{
Whatsapp
whatsapp
=
whatsappBean
.
getWhatsapp
();
if
(
whatsapp
==
null
)
{
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
new
JSONObject
().
put
(
"message"
,
"Not connected."
).
put
(
"status"
,
false
).
toMap
());
}
try
{
if
(
whatsapp
.
isConnected
()){
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
new
JSONObject
().
put
(
"message"
,
"Connected"
).
put
(
"status"
,
true
).
toMap
());
}
else
{
return
ResponseEntity
.
status
(
Response
.
SC_OK
).
body
(
new
JSONObject
().
put
(
"message"
,
"Not connected."
).
put
(
"status"
,
false
).
toMap
());
}
}
catch
(
Exception
e
)
{
logger
.
severe
(
e
.
getMessage
());
return
ResponseEntity
.
status
(
Response
.
SC_INTERNAL_SERVER_ERROR
).
body
(
new
JSONObject
().
put
(
"message"
,
"Status has failed."
).
put
(
"status"
,
false
).
toMap
());
}
}
@PostMapping
(
value
=
"send"
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<?>
send
(
@RequestParam
Map
<
String
,
String
>
payload
,
@RequestParam
Map
<
String
,
MultipartFile
>
files
)
{
Whatsapp
whatsapp
=
whatsappBean
.
getWhatsapp
();
...
...
src/main/java/sacooliveros/whatsappweb/bean/WhatsappBean.java
View file @
0dcde996
...
...
@@ -2,6 +2,7 @@ package sacooliveros.whatsappweb.bean;
import
java.util.Optional
;
import
jakarta.annotation.PostConstruct
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
...
...
@@ -13,7 +14,7 @@ public class WhatsappBean {
Optional
<
Whatsapp
>
w
=
Whatsapp
.
webBuilder
().
lastConnection
().
registered
();
@
Bean
@
PostConstruct
public
Whatsapp
getWhatsapp
()
{
return
w
.
orElse
(
null
);
}
...
...
@@ -24,13 +25,16 @@ public class WhatsappBean {
if
(!
w
.
get
().
isConnected
())
{
w
.
get
().
connect
().
join
();
}
}
else
{
w
=
Optional
.
empty
();
}
}
public
void
setWhatsapp
(
Whatsapp
whatsapp
)
{
w
=
Optional
.
ofNullable
(
whatsapp
);
if
(
whatsapp
!=
null
)
{
w
=
Optional
.
of
(
whatsapp
);
}
else
{
Whatsapp
.
webBuilder
().
lastConnection
().
registered
().
get
().
disconnect
().
join
();
w
=
Optional
.
empty
();
}
}
}
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