Skip to content

ActivitySmithHQ/activitysmith-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

25 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ActivitySmith Go SDK

The ActivitySmith Go SDK provides convenient access to the ActivitySmith API from Go applications.

Documentation

See API reference.

Installation

go get github.com/ActivitySmithHQ/activitysmith-go

Usage

package main

import (
	"log"

	activitysmithsdk "github.com/ActivitySmithHQ/activitysmith-go"
	"github.com/ActivitySmithHQ/activitysmith-go/generated"
)

func main() {
	activitysmith, err := activitysmithsdk.New("YOUR_API_KEY")
	if err != nil {
		log.Fatal(err)
	}

	input := activitysmithsdk.PushNotificationInput{
		Title:   "New subscription ๐Ÿ’ธ",
		Message: "Customer upgraded to Pro plan",
	}

	response, err := activitysmith.Notifications.
		Send(input)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Notified:", response.GetDevicesNotified())
}

Send a Push Notification

Push notification example

Use activitysmith.Notifications.Send with either activitysmithsdk.PushNotificationInput (basic) or generated.PushNotificationRequest (advanced fields like redirection and actions).

input := activitysmithsdk.PushNotificationInput{
	Title:   "New subscription ๐Ÿ’ธ",
	Message: "Customer upgraded to Pro plan",
}

response, err := activitysmith.Notifications.Send(input)
if err != nil {
	log.Fatal(err)
}

log.Println(response.GetSuccess())
log.Println(response.GetDevicesNotified())

Start a Live Activity

Start live activity example

Use activitysmith.LiveActivities.Start with an activitysmithsdk.LiveActivityStartInput.

startInput := activitysmithsdk.LiveActivityStartInput{
	Title:         "Nightly database backup",
	Subtitle:      "create snapshot",
	NumberOfSteps: 3,
	CurrentStep:   1,
	Type:          "segmented_progress",
	Color:         "yellow",
	Channels:      []string{"devs", "ops"}, // Optional
}

start, err := activitysmith.LiveActivities.
	Start(startInput)
if err != nil {
	log.Fatal(err)
}

activityID := start.GetActivityId()

Update a Live Activity

Update live activity example

Use activitysmith.LiveActivities.Update with the activityID from Start.

updateInput := activitysmithsdk.LiveActivityUpdateInput{
	ActivityID:  activityID,
	Title:       "Nightly database backup",
	Subtitle:    "upload archive",
	CurrentStep: 2,
}

update, err := activitysmith.LiveActivities.
	Update(updateInput)
if err != nil {
	log.Fatal(err)
}

log.Println(update.GetDevicesNotified())

End a Live Activity

End live activity example

Use activitysmith.LiveActivities.End to end the activity. If AutoDismissMinutes is omitted, backend default 3 is used.

endInput := activitysmithsdk.LiveActivityEndInput{
	ActivityID:         activityID,
	Title:              "Nightly database backup",
	Subtitle:           "verify restore",
	CurrentStep: 3,
	AutoDismissMinutes: 2,
}

end, err := activitysmith.LiveActivities.
	End(endInput)
if err != nil {
	log.Fatal(err)
}

log.Println(end.GetSuccess())

Channels

Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.

request := generated.NewPushNotificationRequest("New subscription ๐Ÿ’ธ")
request.SetMessage("Customer upgraded to Pro plan")
request.SetTarget(generated.ChannelTarget{Channels: []string{"sales", "customer-success"}}) // Optional

response, err := activitysmith.Notifications.Send(request)
if err != nil {
	log.Fatal(err)
}

log.Println(response.GetSuccess())
log.Println(response.GetDevicesNotified())

Push Notification Redirection and Actions

Push notification redirection and actions are optional and can be used to redirect the user to a specific URL when they tap the notification or to trigger a specific action when they long-press the notification. Webhooks are executed by ActivitySmith backend.

request := generated.NewPushNotificationRequest("New subscription ๐Ÿ’ธ")
request.SetMessage("Customer upgraded to Pro plan")
request.SetRedirection("https://crm.example.com/customers/cus_9f3a1d") // Optional

crmAction := generated.NewPushNotificationAction(
	"Open CRM Profile",
	generated.PUSHNOTIFICATIONACTIONTYPE_OPEN_URL,
	"https://crm.example.com/customers/cus_9f3a1d",
)

onboardingAction := generated.NewPushNotificationAction(
	"Start Onboarding Workflow",
	generated.PUSHNOTIFICATIONACTIONTYPE_WEBHOOK,
	"https://hooks.example.com/activitysmith/onboarding/start",
)
onboardingAction.SetMethod(generated.PUSHNOTIFICATIONACTIONMETHOD_POST)
onboardingAction.SetBody(map[string]interface{}{
	"customer_id": "cus_9f3a1d",
	"plan": "pro",
})

request.SetActions([]generated.PushNotificationAction{
	*crmAction,
	*onboardingAction,
}) // Optional (max 4)

response, err := activitysmith.Notifications.Send(request)
if err != nil {
	log.Fatal(err)
}

log.Println(response.GetSuccess())
log.Println(response.GetDevicesNotified())

Error Handling

SDK methods return (response, error). Always check error on each call.

Requirements

  • Go 1.22+

License

MIT

About

Go library for the ActivitySmith API

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors