activitysmith

package module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAPIKeyRequired = errors.New("activitysmith: apiKey is required")

Functions

This section is empty.

Types

type Client

type Client struct {
	Notifications  *NotificationsService
	LiveActivities *LiveActivitiesService
	// contains filtered or unexported fields
}

func New

func New(apiKey string, opts ...*Options) (*Client, error)

func (*Client) APIClient

func (c *Client) APIClient() *generated.APIClient

func (*Client) Context

func (c *Client) Context() context.Context

type LiveActivitiesService

type LiveActivitiesService struct {
	// contains filtered or unexported fields
}

func (*LiveActivitiesService) End

func (*LiveActivitiesService) EndLiveActivity

func (*LiveActivitiesService) Start

func (*LiveActivitiesService) StartLiveActivity

Backward-compatible aliases.

func (*LiveActivitiesService) Update

func (*LiveActivitiesService) UpdateLiveActivity

type LiveActivityEndInput added in v0.1.1

type LiveActivityEndInput struct {
	ActivityID         string
	Title              string
	CurrentStep        int32
	Subtitle           string
	Color              string
	StepColor          string
	NumberOfSteps      int32
	AutoDismissMinutes int32
	// contains filtered or unexported fields
}

LiveActivityEndInput is a handwritten DX input with plain optional values.

func (LiveActivityEndInput) WithAutoDismissMinutes added in v0.1.1

func (in LiveActivityEndInput) WithAutoDismissMinutes(v int32) LiveActivityEndInput

WithAutoDismissMinutes forces inclusion of auto_dismiss_minutes, including explicit zero.

func (LiveActivityEndInput) WithNumberOfSteps added in v0.1.1

func (in LiveActivityEndInput) WithNumberOfSteps(v int32) LiveActivityEndInput

WithNumberOfSteps forces inclusion of number_of_steps, including explicit zero.

type LiveActivityStartInput added in v0.1.1

type LiveActivityStartInput struct {
	Title         string
	NumberOfSteps int32
	CurrentStep   int32
	Type          string
	Subtitle      string
	Color         string
	StepColor     string
	Channels      []string
}

LiveActivityStartInput is a handwritten DX input with plain optional values.

type LiveActivityUpdateInput added in v0.1.1

type LiveActivityUpdateInput struct {
	ActivityID    string
	Title         string
	CurrentStep   int32
	Subtitle      string
	Color         string
	StepColor     string
	NumberOfSteps int32
	// contains filtered or unexported fields
}

LiveActivityUpdateInput is a handwritten DX input with plain optional values.

func (LiveActivityUpdateInput) WithNumberOfSteps added in v0.1.1

func (in LiveActivityUpdateInput) WithNumberOfSteps(v int32) LiveActivityUpdateInput

WithNumberOfSteps forces inclusion of number_of_steps, including explicit zero.

type NotificationsService

type NotificationsService struct {
	// contains filtered or unexported fields
}

func (*NotificationsService) Send

func (*NotificationsService) SendPushNotification

Backward-compatible alias.

type Options

type Options struct {
	Context context.Context
}

type PushNotificationInput added in v0.1.1

type PushNotificationInput struct {
	Title    string
	Message  string
	Subtitle string
	Channels []string
}

PushNotificationInput is a handwritten DX input with plain optional values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL