File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
saas-modules/twilio-whatsapp
java/com/baeldung/twilio/whatsapp Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 2020 <groupId >org.springframework.boot</groupId >
2121 <artifactId >spring-boot-starter-web</artifactId >
2222 </dependency >
23+ <dependency >
24+ <groupId >org.springframework.boot</groupId >
25+ <artifactId >spring-boot-starter-validation</artifactId >
26+ </dependency >
2327 <dependency >
2428 <groupId >org.springframework.boot</groupId >
2529 <artifactId >spring-boot-configuration-processor</artifactId >
Original file line number Diff line number Diff line change 1+ package com .baeldung .twilio .whatsapp ;
2+
3+ import org .springframework .boot .context .properties .ConfigurationProperties ;
4+ import org .springframework .validation .annotation .Validated ;
5+
6+ import jakarta .validation .Valid ;
7+ import jakarta .validation .constraints .NotBlank ;
8+ import jakarta .validation .constraints .Pattern ;
9+ import lombok .Getter ;
10+ import lombok .Setter ;
11+
12+ @ Getter
13+ @ Setter
14+ @ Validated
15+ @ ConfigurationProperties (prefix = "com.baeldung.twilio" )
16+ public class TwilioConfigurationProperties {
17+
18+ @ NotBlank (message = "Twilio account SID must be configured" )
19+ @ Pattern (regexp = "^AC[0-9a-fA-F]{32}$" , message = "Invalid Twilio account SID format" )
20+ private String accountSid ;
21+
22+ @ NotBlank (message = "Twilio auth token must be configured" )
23+ private String authToken ;
24+
25+ @ NotBlank (message = "Twilio messaging SID must be configured" )
26+ @ Pattern (regexp = "^MG[0-9a-fA-F]{32}$" , message = "Invalid Twilio messaging SID format" )
27+ private String messagingSid ;
28+
29+ @ Valid
30+ private NewArticleNotification newArticleNotification = new NewArticleNotification ();
31+
32+ @ Getter
33+ @ Setter
34+ public class NewArticleNotification {
35+
36+ @ NotBlank (message = "Content SID must be configured" )
37+ @ Pattern (regexp = "^HX[0-9a-fA-F]{32}$" , message = "Invalid content SID format" )
38+ private String contentSid ;
39+
40+ }
41+
42+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .twilio .whatsapp ;
2+
3+ import org .springframework .boot .ApplicationArguments ;
4+ import org .springframework .boot .ApplicationRunner ;
5+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
6+ import org .springframework .stereotype .Component ;
7+
8+ import com .twilio .Twilio ;
9+
10+ import lombok .RequiredArgsConstructor ;
11+
12+ @ Component
13+ @ RequiredArgsConstructor
14+ @ EnableConfigurationProperties (TwilioConfigurationProperties .class )
15+ public class TwilioInitializer implements ApplicationRunner {
16+
17+ private final TwilioConfigurationProperties twilioConfigurationProperties ;
18+
19+ @ Override
20+ public void run (ApplicationArguments args ) {
21+ String accountSid = twilioConfigurationProperties .getAccountSid ();
22+ String authToken = twilioConfigurationProperties .getAuthToken ();
23+ Twilio .init (accountSid , authToken );
24+ }
25+
26+ }
Original file line number Diff line number Diff line change 1+ com :
2+ baeldung :
3+ twilio :
4+ account-sid : ${TWILIO_ACCOUNT_SID}
5+ auth-token : ${TWILIO_AUTH_TOKEN}
6+ messaging-sid : ${TWILIO_MESSAGING_SID}
7+ new-article-notification :
8+ content-sid : ${NEW_ARTICLE_NOTIFICATION_CONTENT_SID}
You can’t perform that action at this time.
0 commit comments