88 "io"
99 "net/http"
1010 "net/url"
11+ "strings"
1112
1213 "github.com/TwiN/gatus/v5/alerting/alert"
1314 "github.com/TwiN/gatus/v5/client"
@@ -27,6 +28,9 @@ type Config struct {
2728 Token string `yaml:"token"`
2829 From string `yaml:"from"`
2930 To string `yaml:"to"`
31+
32+ TextTwilioTriggered string `yaml:"text-twilio-triggered,omitempty"` // String used in the SMS body and subject (optional)
33+ TextTwilioResolved string `yaml:"text-twilio-resolved,omitempty"` // String used in the SMS body and subject (optional)
3034}
3135
3236func (cfg * Config ) Validate () error {
@@ -58,6 +62,12 @@ func (cfg *Config) Merge(override *Config) {
5862 if len (override .To ) > 0 {
5963 cfg .To = override .To
6064 }
65+ if len (override .TextTwilioTriggered ) > 0 {
66+ cfg .TextTwilioTriggered = override .TextTwilioTriggered
67+ }
68+ if len (override .TextTwilioResolved ) > 0 {
69+ cfg .TextTwilioResolved = override .TextTwilioResolved
70+ }
6171}
6272
6373// AlertProvider is the configuration necessary for sending an alert using Twilio
@@ -102,9 +112,17 @@ func (provider *AlertProvider) Send(ep *endpoint.Endpoint, alert *alert.Alert, r
102112func (provider * AlertProvider ) buildRequestBody (cfg * Config , ep * endpoint.Endpoint , alert * alert.Alert , result * endpoint.Result , resolved bool ) string {
103113 var message string
104114 if resolved {
105- message = fmt .Sprintf ("RESOLVED: %s - %s" , ep .DisplayName (), alert .GetDescription ())
115+ if len (cfg .TextTwilioResolved ) > 0 {
116+ message = strings .Replace (strings .Replace (cfg .TextTwilioResolved , "{endpoint}" , ep .DisplayName (), 1 ), "{description}" , alert .GetDescription (), 1 )
117+ } else {
118+ message = fmt .Sprintf ("RESOLVED: %s - %s" , ep .DisplayName (), alert .GetDescription ())
119+ }
106120 } else {
107- message = fmt .Sprintf ("TRIGGERED: %s - %s" , ep .DisplayName (), alert .GetDescription ())
121+ if len (cfg .TextTwilioTriggered ) > 0 {
122+ message = strings .Replace (strings .Replace (cfg .TextTwilioTriggered , "{endpoint}" , ep .DisplayName (), 1 ), "{description}" , alert .GetDescription (), 1 )
123+ } else {
124+ message = fmt .Sprintf ("TRIGGERED: %s - %s" , ep .DisplayName (), alert .GetDescription ())
125+ }
108126 }
109127 return url.Values {
110128 "To" : {cfg .To },
0 commit comments