-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
111 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package smsgateway | ||
|
||
import "time" | ||
|
||
// Device | ||
type Device struct { | ||
ID string `json:"id" example:"PyDmBQZZXYmyxMwED8Fzy"` // ID | ||
Name string `json:"name" example:"My Device"` // Name | ||
CreatedAt time.Time `json:"createdAt" example:"2020-01-01T00:00:00Z"` // Created at (read only) | ||
UpdatedAt time.Time `json:"updatedAt" example:"2020-01-01T00:00:00Z"` // Updated at (read only) | ||
DeletedAt *time.Time `json:"deletedAt,omitempty" example:"2020-01-01T00:00:00Z"` // Deleted at (read only) | ||
|
||
LastSeen time.Time `json:"lastSeen" example:"2020-01-01T00:00:00Z"` // Last seen at (read only) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,45 @@ | ||
package smsgateway | ||
|
||
import "github.com/android-sms-gateway/client-go/smsgateway/webhooks" | ||
|
||
// Deprecated: use webhooks package instead. | ||
type WebhookEvent = webhooks.EventType | ||
type WebhookEvent = string | ||
|
||
const ( | ||
// Deprecated: use webhooks package instead. | ||
WebhookEventSmsReceived WebhookEvent = webhooks.EventTypeSmsReceived | ||
// Deprecated: use webhooks package instead. | ||
WebhookEventSystemPing WebhookEvent = webhooks.EventTypeSystemPing | ||
// Triggered when an SMS is received. | ||
WebhookEventSmsReceived WebhookEvent = "sms:received" | ||
// Triggered when an SMS is sent. | ||
WebhookEventSmsSent WebhookEvent = "sms:sent" | ||
// Triggered when an SMS is delivered. | ||
WebhookEventSmsDelivered WebhookEvent = "sms:delivered" | ||
// Triggered when an SMS processing fails. | ||
WebhookEventSmsFailed WebhookEvent = "sms:failed" | ||
// Triggered when the device pings the server. | ||
WebhookEventSystemPing WebhookEvent = "system:ping" | ||
) | ||
|
||
// Deprecated: use webhook package instead. | ||
type Webhook = webhooks.Webhook | ||
var allEventTypes = map[WebhookEvent]struct{}{ | ||
WebhookEventSmsReceived: {}, | ||
WebhookEventSmsSent: {}, | ||
WebhookEventSmsDelivered: {}, | ||
WebhookEventSmsFailed: {}, | ||
WebhookEventSystemPing: {}, | ||
} | ||
|
||
// IsValid checks if the given event type is valid. | ||
// | ||
// e is the event type to be checked. | ||
// Returns true if the event type is valid, false otherwise. | ||
func IsValidWebhookEvent(e WebhookEvent) bool { | ||
_, ok := allEventTypes[e] | ||
return ok | ||
} | ||
|
||
// A webhook configuration. | ||
type Webhook struct { | ||
// The unique identifier of the webhook. | ||
ID string `json:"id" validate:"max=36" example:"123e4567-e89b-12d3-a456-426614174000"` | ||
|
||
// The URL the webhook will be sent to. | ||
URL string `json:"url" validate:"required,http_url" example:"https://example.com/webhook"` | ||
|
||
// The type of event the webhook is triggered for. | ||
Event WebhookEvent `json:"event" validate:"required" example:"sms:received"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package smsgateway_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/android-sms-gateway/client-go/smsgateway" | ||
) | ||
|
||
// TestIsValidEventType tests the IsValidEventType function. | ||
func TestIsValidEventType(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e smsgateway.WebhookEvent | ||
want bool | ||
}{ | ||
{ | ||
name: "Valid event type", | ||
e: smsgateway.WebhookEventSmsDelivered, | ||
want: true, | ||
}, | ||
{ | ||
name: "Invalid event type", | ||
e: "invalid:event", | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := smsgateway.IsValidWebhookEvent(tt.e); got != tt.want { | ||
t.Errorf("IsValid() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,27 @@ | ||
package webhooks | ||
|
||
type EventType string | ||
import "github.com/android-sms-gateway/client-go/smsgateway" | ||
|
||
// Deprecated: use smsgateway package instead. | ||
type EventType = smsgateway.WebhookEvent | ||
|
||
const ( | ||
// Triggered when an SMS is received. | ||
EventTypeSmsReceived EventType = "sms:received" | ||
// Triggered when an SMS is sent. | ||
EventTypeSmsSent EventType = "sms:sent" | ||
// Triggered when an SMS is delivered. | ||
EventTypeSmsDelivered EventType = "sms:delivered" | ||
// Triggered when an SMS processing fails. | ||
EventTypeSmsFailed EventType = "sms:failed" | ||
// Triggered when the device pings the server. | ||
EventTypeSystemPing EventType = "system:ping" | ||
// Deprecated: use smsgateway package instead. | ||
EventTypeSmsReceived EventType = smsgateway.WebhookEventSmsReceived | ||
// Deprecated: use smsgateway package instead. | ||
EventTypeSmsSent EventType = smsgateway.WebhookEventSmsSent | ||
// Deprecated: use smsgateway package instead. | ||
EventTypeSmsDelivered EventType = smsgateway.WebhookEventSmsDelivered | ||
// Deprecated: use smsgateway package instead. | ||
EventTypeSmsFailed EventType = smsgateway.WebhookEventSmsFailed | ||
// Deprecated: use smsgateway package instead. | ||
EventTypeSystemPing EventType = smsgateway.WebhookEventSystemPing | ||
) | ||
|
||
var allEventTypes = map[EventType]struct{}{ | ||
EventTypeSmsReceived: {}, | ||
EventTypeSmsSent: {}, | ||
EventTypeSmsDelivered: {}, | ||
EventTypeSmsFailed: {}, | ||
EventTypeSystemPing: {}, | ||
} | ||
|
||
// IsValid checks if the given event type is valid. | ||
// | ||
// e is the event type to be checked. | ||
// Returns true if the event type is valid, false otherwise. | ||
// Deprecated: use smsgateway package instead. | ||
func IsValidEventType(e EventType) bool { | ||
_, ok := allEventTypes[e] | ||
return ok | ||
return smsgateway.IsValidWebhookEvent(e) | ||
} | ||
|
||
// A webhook configuration. | ||
type Webhook struct { | ||
// The unique identifier of the webhook. | ||
ID string `json:"id" validate:"max=36" example:"123e4567-e89b-12d3-a456-426614174000"` | ||
|
||
// The URL the webhook will be sent to. | ||
URL string `json:"url" validate:"required,http_url" example:"https://example.com/webhook"` | ||
|
||
// The type of event the webhook is triggered for. | ||
Event EventType `json:"event" validate:"required" example:"sms:received"` | ||
} | ||
// Deprecated: use smsgateway package instead. | ||
type Webhook = smsgateway.Webhook |