File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
saas-modules/twilio-whatsapp
src/main/java/com/baeldung/twilio/whatsapp Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 3939 <artifactId >twilio</artifactId >
4040 <version >${twilio.version} </version >
4141 </dependency >
42+ <dependency >
43+ <groupId >org.json</groupId >
44+ <artifactId >json</artifactId >
45+ <version >${json.version} </version >
46+ </dependency >
4247 </dependencies >
4348
4449 <properties >
4550 <java .version>17</java .version>
51+ <json .version>20240303</json .version>
4652 <twilio .version>10.4.1</twilio .version>
4753 </properties >
4854
Original file line number Diff line number Diff line change 1+ package com .baeldung .twilio .whatsapp ;
2+
3+ import org .json .JSONObject ;
4+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
5+ import org .springframework .stereotype .Service ;
6+
7+ import com .twilio .rest .api .v2010 .account .Message ;
8+ import com .twilio .type .PhoneNumber ;
9+
10+ import lombok .RequiredArgsConstructor ;
11+
12+ @ Service
13+ @ RequiredArgsConstructor
14+ @ EnableConfigurationProperties (TwilioConfigurationProperties .class )
15+ public class ArticlePublishedNotificationDispatcher {
16+
17+ private final TwilioConfigurationProperties twilioConfigurationProperties ;
18+
19+ public void dispatch (String phoneNumber , String articleUrl ) {
20+ String messagingSid = twilioConfigurationProperties .getMessagingSid ();
21+ String contentSid = twilioConfigurationProperties .getNewArticleNotification ().getContentSid ();
22+ PhoneNumber toPhoneNumber = new PhoneNumber (String .format ("whatsapp:%s" , phoneNumber ));
23+
24+ JSONObject contentVariables = new JSONObject ();
25+ contentVariables .put ("ArticleURL" , articleUrl );
26+
27+ Message .creator (toPhoneNumber , messagingSid , "" )
28+ .setContentSid (contentSid )
29+ .setContentVariables (contentVariables .toString ())
30+ .create ();
31+ }
32+
33+ }
You can’t perform that action at this time.
0 commit comments