From 3b3e6ac2cd7e9e9b635158a47dcf5e39e1884d87 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Thu, 18 May 2023 13:32:27 -0400 Subject: [PATCH] Rename twilio-from-number to twilio-phone-number --- cmd/serve.go | 10 +++++----- docs/config.md | 4 ++-- server/config.go | 4 ++-- server/server.yml | 4 ++-- server/server_test.go | 2 +- server/server_twilio.go | 2 +- server/server_twilio_test.go | 12 ++++++------ 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index a3263742..5d5381bf 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -74,7 +74,7 @@ var flagsServe = append( altsrc.NewStringFlag(&cli.StringFlag{Name: "smtp-server-addr-prefix", Aliases: []string{"smtp_server_addr_prefix"}, EnvVars: []string{"NTFY_SMTP_SERVER_ADDR_PREFIX"}, Usage: "SMTP email address prefix for topics to prevent spam (e.g. 'ntfy-')"}), altsrc.NewStringFlag(&cli.StringFlag{Name: "twilio-account", Aliases: []string{"twilio_account"}, EnvVars: []string{"NTFY_TWILIO_ACCOUNT"}, Usage: "Twilio account SID, used for phone calls, e.g. AC123..."}), altsrc.NewStringFlag(&cli.StringFlag{Name: "twilio-auth-token", Aliases: []string{"twilio_auth_token"}, EnvVars: []string{"NTFY_TWILIO_AUTH_TOKEN"}, Usage: "Twilio auth token"}), - altsrc.NewStringFlag(&cli.StringFlag{Name: "twilio-from-number", Aliases: []string{"twilio_from_number"}, EnvVars: []string{"NTFY_TWILIO_FROM_NUMBER"}, Usage: "Twilio number to use for outgoing calls"}), + altsrc.NewStringFlag(&cli.StringFlag{Name: "twilio-phone-number", Aliases: []string{"twilio_phone_number"}, EnvVars: []string{"NTFY_TWILIO_PHONE_NUMBER"}, Usage: "Twilio number to use for outgoing calls"}), altsrc.NewStringFlag(&cli.StringFlag{Name: "twilio-verify-service", Aliases: []string{"twilio_verify_service"}, EnvVars: []string{"NTFY_TWILIO_VERIFY_SERVICE"}, Usage: "Twilio Verify service ID, used for phone number verification"}), altsrc.NewIntFlag(&cli.IntFlag{Name: "global-topic-limit", Aliases: []string{"global_topic_limit", "T"}, EnvVars: []string{"NTFY_GLOBAL_TOPIC_LIMIT"}, Value: server.DefaultTotalTopicLimit, Usage: "total number of topics allowed"}), altsrc.NewIntFlag(&cli.IntFlag{Name: "visitor-subscription-limit", Aliases: []string{"visitor_subscription_limit"}, EnvVars: []string{"NTFY_VISITOR_SUBSCRIPTION_LIMIT"}, Value: server.DefaultVisitorSubscriptionLimit, Usage: "number of subscriptions per visitor"}), @@ -159,7 +159,7 @@ func execServe(c *cli.Context) error { smtpServerAddrPrefix := c.String("smtp-server-addr-prefix") twilioAccount := c.String("twilio-account") twilioAuthToken := c.String("twilio-auth-token") - twilioFromNumber := c.String("twilio-from-number") + twilioPhoneNumber := c.String("twilio-phone-number") twilioVerifyService := c.String("twilio-verify-service") totalTopicLimit := c.Int("global-topic-limit") visitorSubscriptionLimit := c.Int("visitor-subscription-limit") @@ -219,8 +219,8 @@ func execServe(c *cli.Context) error { return errors.New("cannot set enable-signup without also setting enable-login") } else if stripeSecretKey != "" && (stripeWebhookKey == "" || baseURL == "") { return errors.New("if stripe-secret-key is set, stripe-webhook-key and base-url must also be set") - } else if twilioAccount != "" && (twilioAuthToken == "" || twilioFromNumber == "" || twilioVerifyService == "" || baseURL == "" || authFile == "") { - return errors.New("if twilio-account is set, twilio-auth-token, twilio-from-number, twilio-verify-service, base-url, and auth-file must also be set") + } else if twilioAccount != "" && (twilioAuthToken == "" || twilioPhoneNumber == "" || twilioVerifyService == "" || baseURL == "" || authFile == "") { + return errors.New("if twilio-account is set, twilio-auth-token, twilio-phone-number, twilio-verify-service, base-url, and auth-file must also be set") } // Backwards compatibility @@ -323,7 +323,7 @@ func execServe(c *cli.Context) error { conf.SMTPServerAddrPrefix = smtpServerAddrPrefix conf.TwilioAccount = twilioAccount conf.TwilioAuthToken = twilioAuthToken - conf.TwilioFromNumber = twilioFromNumber + conf.TwilioPhoneNumber = twilioPhoneNumber conf.TwilioVerifyService = twilioVerifyService conf.TotalTopicLimit = totalTopicLimit conf.VisitorSubscriptionLimit = visitorSubscriptionLimit diff --git a/docs/config.md b/docs/config.md index 66301ee0..df1f2cd6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -866,7 +866,7 @@ are the easiest), and then configure the following options: * `twilio-account` is the Twilio account SID, e.g. AC12345beefbeef67890beefbeef122586 * `twilio-auth-token` is the Twilio auth token, e.g. affebeef258625862586258625862586 -* `twilio-from-number` is the outgoing phone number you purchased, e.g. +18775132586 +* `twilio-phone-number` is the outgoing phone number you purchased, e.g. +18775132586 * `twilio-verify-service` is the Twilio Verify service SID, e.g. VA12345beefbeef67890beefbeef122586 After you have configured phone calls, create a [tier](#tiers) with a call limit (e.g. `ntfy tier create --call-limit=10 ...`), @@ -1261,7 +1261,7 @@ variable before running the `ntfy` command (e.g. `export NTFY_LISTEN_HTTP=:80`). | `smtp-server-addr-prefix` | `NTFY_SMTP_SERVER_ADDR_PREFIX` | *string* | - | Optional prefix for the e-mail addresses to prevent spam, e.g. `ntfy-` | | `twilio-account` | `NTFY_TWILIO_ACCOUNT` | *string* | - | Twilio account SID, e.g. AC12345beefbeef67890beefbeef122586 | | `twilio-auth-token` | `NTFY_TWILIO_AUTH_TOKEN` | *string* | - | Twilio auth token, e.g. affebeef258625862586258625862586 | -| `twilio-from-number` | `NTFY_TWILIO_FROM_NUMBER` | *string* | - | Twilio outgoing phone number, e.g. +18775132586 | +| `twilio-phone-number` | `NTFY_TWILIO_PHONE_NUMBER` | *string* | - | Twilio outgoing phone number, e.g. +18775132586 | | `twilio-verify-service` | `NTFY_TWILIO_VERIFY_SERVICE` | *string* | - | Twilio Verify service SID, e.g. VA12345beefbeef67890beefbeef122586 | | `keepalive-interval` | `NTFY_KEEPALIVE_INTERVAL` | *duration* | 45s | Interval in which keepalive messages are sent to the client. This is to prevent intermediaries closing the connection for inactivity. Note that the Android app has a hardcoded timeout at 77s, so it should be less than that. | | `manager-interval` | `NTFY_MANAGER_INTERVAL` | *duration* | 1m | Interval in which the manager prunes old messages, deletes topics and prints the stats. | diff --git a/server/config.go b/server/config.go index ae962719..a876926e 100644 --- a/server/config.go +++ b/server/config.go @@ -108,7 +108,7 @@ type Config struct { SMTPServerAddrPrefix string TwilioAccount string TwilioAuthToken string - TwilioFromNumber string + TwilioPhoneNumber string TwilioCallsBaseURL string TwilioVerifyBaseURL string TwilioVerifyService string @@ -194,7 +194,7 @@ func NewConfig() *Config { TwilioCallsBaseURL: "https://api.twilio.com", // Override for tests TwilioAccount: "", TwilioAuthToken: "", - TwilioFromNumber: "", + TwilioPhoneNumber: "", TwilioVerifyBaseURL: "https://verify.twilio.com", // Override for tests TwilioVerifyService: "", MessageLimit: DefaultMessageLengthLimit, diff --git a/server/server.yml b/server/server.yml index 2f16fc86..9c7972e9 100644 --- a/server/server.yml +++ b/server/server.yml @@ -148,12 +148,12 @@ # # - twilio-account is the Twilio account SID, e.g. AC12345beefbeef67890beefbeef122586 # - twilio-auth-token is the Twilio auth token, e.g. affebeef258625862586258625862586 -# - twilio-from-number is the outgoing phone number you purchased, e.g. +18775132586 +# - twilio-phone-number is the outgoing phone number you purchased, e.g. +18775132586 # - twilio-verify-service is the Twilio Verify service SID, e.g. VA12345beefbeef67890beefbeef122586 # # twilio-account: # twilio-auth-token: -# twilio-from-number: +# twilio-phone-number: # twilio-verify-service: # Interval in which keepalive messages are sent to the client. This is to prevent diff --git a/server/server_test.go b/server/server_test.go index 0cdb490c..35d89707 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1198,7 +1198,7 @@ func TestServer_PublishDelayedCall_Fail(t *testing.T) { c := newTestConfigWithAuthFile(t) c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" s := newTestServer(t, c) response := request(t, s, "PUT", "/mytopic", "fail", map[string]string{ "Call": "yes", diff --git a/server/server_twilio.go b/server/server_twilio.go index b557edf4..093abe63 100644 --- a/server/server_twilio.go +++ b/server/server_twilio.go @@ -67,7 +67,7 @@ func (s *Server) callPhone(v *visitor, r *http.Request, m *message, to string) { } body := fmt.Sprintf(twilioCallFormat, xmlEscapeText(m.Topic), xmlEscapeText(m.Message), xmlEscapeText(sender)) data := url.Values{} - data.Set("From", s.config.TwilioFromNumber) + data.Set("From", s.config.TwilioPhoneNumber) data.Set("To", to) data.Set("Twiml", body) ev := logvrm(v, r, m).Tag(tagTwilio).Field("twilio_to", to).FieldIf("twilio_body", body, log.TraceLevel).Debug("Sending Twilio request") diff --git a/server/server_twilio_test.go b/server/server_twilio_test.go index 1b710130..af694a77 100644 --- a/server/server_twilio_test.go +++ b/server/server_twilio_test.go @@ -53,7 +53,7 @@ func TestServer_Twilio_Call_Add_Verify_Call_Delete_Success(t *testing.T) { c.TwilioCallsBaseURL = twilioCallsServer.URL c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" c.TwilioVerifyService = "VA1234567890" s := newTestServer(t, c) @@ -131,7 +131,7 @@ func TestServer_Twilio_Call_Success(t *testing.T) { c.TwilioCallsBaseURL = twilioServer.URL c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" s := newTestServer(t, c) // Add tier and user @@ -176,7 +176,7 @@ func TestServer_Twilio_Call_Success_With_Yes(t *testing.T) { c.TwilioCallsBaseURL = twilioServer.URL c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" s := newTestServer(t, c) // Add tier and user @@ -207,7 +207,7 @@ func TestServer_Twilio_Call_UnverifiedNumber(t *testing.T) { c.TwilioCallsBaseURL = "http://dummy.invalid" c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" s := newTestServer(t, c) // Add tier and user @@ -232,7 +232,7 @@ func TestServer_Twilio_Call_InvalidNumber(t *testing.T) { c.TwilioCallsBaseURL = "https://127.0.0.1" c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" s := newTestServer(t, c) response := request(t, s, "POST", "/mytopic", "test", map[string]string{ @@ -246,7 +246,7 @@ func TestServer_Twilio_Call_Anonymous(t *testing.T) { c.TwilioCallsBaseURL = "https://127.0.0.1" c.TwilioAccount = "AC1234567890" c.TwilioAuthToken = "AAEAA1234567890" - c.TwilioFromNumber = "+1234567890" + c.TwilioPhoneNumber = "+1234567890" s := newTestServer(t, c) response := request(t, s, "POST", "/mytopic", "test", map[string]string{