Skip to content

Latest commit

 

History

History
357 lines (290 loc) · 18.5 KB

README.md

File metadata and controls

357 lines (290 loc) · 18.5 KB

Novu SDK

Overview

Novu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.

Novu Documentation https://docs.novu.co

Available Operations

Trigger

Trigger event is the main (and only) way to send notifications to subscribers. 
The trigger identifier is used to match the particular workflow associated with it. 
Additional information can be passed according the body interface below.

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_SECRET_KEY")),
    )

    res, err := s.Trigger(ctx, components.TriggerEventRequestDto{
        WorkflowID: "workflow_identifier",
        Payload: map[string]any{
            "comment_id": "string",
            "post": map[string]any{
                "text": "string",
            },
        },
        Overrides: map[string]map[string]any{
            "fcm": map[string]any{
                "data": map[string]any{
                    "key": "value",
                },
            },
        },
        To: components.CreateToSubscriberPayloadDto(
            components.SubscriberPayloadDto{
                SubscriberID: "<id>",
            },
        ),
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.TriggerEventResponseDto != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
triggerEventRequestDto components.TriggerEventRequestDto ✔️ N/A
idempotencyKey *string A header for idempotency purposes
opts []operations.Option The options for this request.

Response

*operations.EventsControllerTriggerResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 414 application/json
apierrors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.ErrorDto 500 application/json
apierrors.APIError 4XX, 5XX */*

TriggerBulk

  Using this endpoint you can trigger multiple events at once, to avoid multiple calls to the API.
  The bulk API is limited to 100 events per request.

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_SECRET_KEY")),
    )

    res, err := s.TriggerBulk(ctx, components.BulkTriggerEventDto{
        Events: []components.TriggerEventRequestDto{
            components.TriggerEventRequestDto{
                WorkflowID: "workflow_identifier",
                Payload: map[string]any{
                    "comment_id": "string",
                    "post": map[string]any{
                        "text": "string",
                    },
                },
                Overrides: map[string]map[string]any{
                    "fcm": map[string]any{
                        "data": map[string]any{
                            "key": "value",
                        },
                    },
                },
                To: components.CreateToSubscriberPayloadDto(
                    components.SubscriberPayloadDto{
                        SubscriberID: "<id>",
                    },
                ),
            },
            components.TriggerEventRequestDto{
                WorkflowID: "workflow_identifier",
                Payload: map[string]any{
                    "comment_id": "string",
                    "post": map[string]any{
                        "text": "string",
                    },
                },
                Overrides: map[string]map[string]any{
                    "fcm": map[string]any{
                        "data": map[string]any{
                            "key": "value",
                        },
                    },
                },
                To: components.CreateToArrayOf1(
                    []components.One{
                        components.CreateOneTopicPayloadDto(
                            components.TopicPayloadDto{
                                TopicKey: "<value>",
                                Type: components.TriggerRecipientsTypeEnumSubscriber,
                            },
                        ),
                    },
                ),
            },
            components.TriggerEventRequestDto{
                WorkflowID: "workflow_identifier",
                Payload: map[string]any{
                    "comment_id": "string",
                    "post": map[string]any{
                        "text": "string",
                    },
                },
                Overrides: map[string]map[string]any{
                    "fcm": map[string]any{
                        "data": map[string]any{
                            "key": "value",
                        },
                    },
                },
                To: components.CreateToArrayOf1(
                    []components.One{
                        components.CreateOneStr(
                            "SUBSCRIBER_ID",
                        ),
                        components.CreateOneStr(
                            "SUBSCRIBER_ID",
                        ),
                    },
                ),
            },
        },
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.TriggerEventResponseDtos != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
bulkTriggerEventDto components.BulkTriggerEventDto ✔️ N/A
idempotencyKey *string A header for idempotency purposes
opts []operations.Option The options for this request.

Response

*operations.EventsControllerTriggerBulkResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 414 application/json
apierrors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.ErrorDto 500 application/json
apierrors.APIError 4XX, 5XX */*

TriggerBroadcast

Trigger a broadcast event to all existing subscribers, could be used to send announcements, etc. In the future could be used to trigger events to a subset of subscribers based on defined filters.

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_SECRET_KEY")),
    )

    res, err := s.TriggerBroadcast(ctx, components.TriggerEventToAllRequestDto{
        Name: "<value>",
        Payload: map[string]any{
            "comment_id": "string",
            "post": map[string]any{
                "text": "string",
            },
        },
    }, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.TriggerEventResponseDto != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
triggerEventToAllRequestDto components.TriggerEventToAllRequestDto ✔️ N/A
idempotencyKey *string A header for idempotency purposes
opts []operations.Option The options for this request.

Response

*operations.EventsControllerBroadcastEventToAllResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 414 application/json
apierrors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.ErrorDto 500 application/json
apierrors.APIError 4XX, 5XX */*

Cancel

Using a previously generated transactionId during the event trigger,
 will cancel any active or pending workflows. This is useful to cancel active digests, delays etc...

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_SECRET_KEY")),
    )

    res, err := s.Cancel(ctx, "<id>", nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.DataBooleanDto != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
transactionID string ✔️ N/A
idempotencyKey *string A header for idempotency purposes
opts []operations.Option The options for this request.

Response

*operations.EventsControllerCancelResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 414 application/json
apierrors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.ErrorDto 500 application/json
apierrors.APIError 4XX, 5XX */*