Skip to content

Commit 8c3081b

Browse files
authored
Merge pull request #22 from tybritten/master
Add FreshChat URN
2 parents 1d7c5b9 + 295257e commit 8c3081b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

urns/urns.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const (
2323
// FCMScheme is the scheme used for Firebase Cloud Messaging identifiers
2424
FCMScheme string = "fcm"
2525

26+
// FreshChatScheme is the scheme used for FreshChat Cloud Messaging identifiers
27+
FreshChatScheme string = "freshchat"
28+
2629
// JiochatScheme is the scheme used for Jiochat identifiers
2730
JiochatScheme string = "jiochat"
2831

@@ -60,6 +63,7 @@ var ValidSchemes = map[string]bool{
6063
ExternalScheme: true,
6164
FacebookScheme: true,
6265
FCMScheme: true,
66+
FreshChatScheme: true,
6367
JiochatScheme: true,
6468
LineScheme: true,
6569
TelegramScheme: true,
@@ -84,6 +88,7 @@ var emailRegex = regexp.MustCompile(`^[^\s@]+@[^\s@]+$`)
8488
var viberRegex = regexp.MustCompile(`^[a-zA-Z0-9_=/+]{1,24}$`)
8589
var lineRegex = regexp.MustCompile(`^[a-zA-Z0-9_]{1,36}$`)
8690
var allDigitsRegex = regexp.MustCompile(`^[0-9]+$`)
91+
var freshchatRegex = regexp.MustCompile(`^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$`)
8792

8893
// URN represents a Universal Resource Name, we use this for contact identifiers like phone numbers etc..
8994
type URN string
@@ -249,9 +254,15 @@ func (u URN) Validate() error {
249254
if !allDigitsRegex.MatchString(path) {
250255
return fmt.Errorf("invalid whatsapp id: %s", path)
251256
}
252-
}
253257

258+
case FreshChatScheme:
259+
// validate path and query is a uuid
260+
if !freshchatRegex.MatchString(path) {
261+
return fmt.Errorf("invalid freshchat id: %s", path)
262+
}
263+
}
254264
return nil // anything goes for external schemes
265+
255266
}
256267

257268
// Scheme returns the scheme portion for the URN

urns/urns_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func TestValidate(t *testing.T) {
212212

213213
// invalid tel numbers
214214
{"tel:07883 83383", "invalid tel number"}, // can't have spaces
215-
{"tel:", "cannot be empty"}, // need a path
215+
{"tel:", "cannot be empty"}, // need a path
216216

217217
// twitter handles
218218
{"twitter:jimmyjo", ""},
@@ -259,6 +259,11 @@ func TestValidate(t *testing.T) {
259259
{"whatsapp:12354", ""},
260260
{"whatsapp:abcde", "invalid whatsapp id"},
261261
{"whatsapp:+12067799294", "invalid whatsapp id"},
262+
263+
// freschat has to be two uuids separated by a colon
264+
{"freshchat:6a2f41a3-c54c-fce8-32d2-0324e1c32e22/6a2f41a3-c54c-fce8-32d2-0324e1c32e22", ""},
265+
{"freshchat:6a2f41a3-c54c-fce8-32d2-0324e1c32e22", "invalid freshchat id"},
266+
{"freshchat:+12067799294", "invalid freshchat id"},
262267
}
263268

264269
for _, tc := range testCases {

0 commit comments

Comments
 (0)