diff --git a/backends/rapidpro/channel.go b/backends/rapidpro/channel.go index f33323619..59b7737d5 100644 --- a/backends/rapidpro/channel.go +++ b/backends/rapidpro/channel.go @@ -9,6 +9,7 @@ import ( "github.com/lib/pq" "github.com/nyaruka/courier" "github.com/nyaruka/gocommon/i18n" + "github.com/nyaruka/gocommon/urns" "github.com/nyaruka/null/v3" ) @@ -60,8 +61,8 @@ func (c *Channel) ChannelAddress() courier.ChannelAddress { func (c *Channel) Country() i18n.Country { return i18n.Country(c.Country_.String) } // IsScheme returns whether this channel serves only the passed in scheme -func (c *Channel) IsScheme(scheme string) bool { - return len(c.Schemes_) == 1 && c.Schemes_[0] == scheme +func (c *Channel) IsScheme(scheme *urns.Scheme) bool { + return len(c.Schemes_) == 1 && c.Schemes_[0] == scheme.Prefix } // Roles returns the roles of this channel diff --git a/channel.go b/channel.go index dc881844c..a63111510 100644 --- a/channel.go +++ b/channel.go @@ -5,6 +5,7 @@ import ( "errors" "github.com/nyaruka/gocommon/i18n" + "github.com/nyaruka/gocommon/urns" "github.com/nyaruka/gocommon/uuids" "github.com/nyaruka/null/v3" ) @@ -131,7 +132,7 @@ type Channel interface { Roles() []ChannelRole // is this channel for the passed in scheme (and only that scheme) - IsScheme(string) bool + IsScheme(*urns.Scheme) bool // CallbackDomain returns the domain that should be used for any callbacks the channel registers CallbackDomain(fallbackDomain string) string diff --git a/handlers/twiml/handlers.go b/handlers/twiml/handlers.go index 3be7e41f3..b81824d52 100644 --- a/handlers/twiml/handlers.go +++ b/handlers/twiml/handlers.go @@ -137,7 +137,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w } text := form.Body - if channel.IsScheme(urns.WhatsApp.Prefix) && form.ButtonText != "" { + if channel.IsScheme(urns.WhatsApp) && form.ButtonText != "" { text = form.ButtonText } @@ -260,7 +260,7 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen } // for whatsapp channels, we have to prepend whatsapp to the To and From - if channel.IsScheme(urns.WhatsApp.Prefix) { + if channel.IsScheme(urns.WhatsApp) { form["To"][0] = fmt.Sprintf("%s:+%s", urns.WhatsApp.Prefix, form["To"][0]) form["From"][0] = fmt.Sprintf("%s:%s", urns.WhatsApp.Prefix, form["From"][0]) } @@ -348,7 +348,7 @@ func (h *handler) RedactValues(ch courier.Channel) []string { } func (h *handler) parseURN(channel courier.Channel, text string, country i18n.Country) (urns.URN, error) { - if channel.IsScheme(urns.WhatsApp.Prefix) { + if channel.IsScheme(urns.WhatsApp) { // Twilio Whatsapp from is in the form: whatsapp:+12211414154 or +12211414154 var fromTel string parts := strings.Split(text, ":") diff --git a/test/channel.go b/test/channel.go index d46066524..3ae284fb5 100644 --- a/test/channel.go +++ b/test/channel.go @@ -38,8 +38,8 @@ func (c *MockChannel) SetScheme(scheme string) { c.schemes = []string{scheme} } func (c *MockChannel) Schemes() []string { return c.schemes } // IsScheme returns whether the passed in scheme is the scheme for this channel -func (c *MockChannel) IsScheme(scheme string) bool { - return len(c.schemes) == 1 && c.schemes[0] == scheme +func (c *MockChannel) IsScheme(scheme *urns.Scheme) bool { + return len(c.schemes) == 1 && c.schemes[0] == scheme.Prefix } // Address returns the address as a string of this channel