d02173442c
* Add io.sendEvents * Add examples to built-ins catalog entry * Add docs * Add changeset --------- Co-authored-by: Matt Aitken <matt@mattaitken.com>
58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
---
|
|
title: "TriggerClient: sendEvent() instance method"
|
|
sidebarTitle: "sendEvent()"
|
|
description: "The `sendEvent()` instance method send an event that triggers any Jobs that are listening for that event (based on the name)."
|
|
---
|
|
|
|
You can call this function from anywhere in your backend to send an event. The other way to send an event is by using [io.sendEvent()](/sdk/io/sendevent) from inside a `run()` function.
|
|
|
|
Use [eventTrigger()](/sdk/eventtrigger) on a Job to listen for events.
|
|
|
|
For multiple events, use [client.sendEvents()](/sdk/triggerclient/instancemethods/sendevents) instead.
|
|
|
|
## Parameters
|
|
|
|
<Snippet file="send-event-params.mdx" />
|
|
|
|
## Returns
|
|
|
|
<Snippet file="send-event-return.mdx" />
|
|
|
|
<RequestExample>
|
|
|
|
```ts Simple example with a payload
|
|
const event = client.sendEvent({
|
|
name: "new.user",
|
|
payload: {
|
|
userId: "u_1234567890",
|
|
},
|
|
});
|
|
```
|
|
|
|
```ts Send an event with an ID
|
|
const event = client.sendEvent({
|
|
id: "e_1234567890", // You can use this to deduplicate events
|
|
name: "new.user",
|
|
payload: {
|
|
userId: "u_1234567890",
|
|
},
|
|
});
|
|
```
|
|
|
|
```ts Send an event to be delivered later
|
|
const event = client.sendEvent(
|
|
{
|
|
id: "e_1234567890", // You can use this to deduplicate events
|
|
name: "new.user",
|
|
payload: {
|
|
userId: "u_1234567890",
|
|
},
|
|
},
|
|
{
|
|
deliverAt: new Date("2023-12-01T00:00:00.000Z"),
|
|
}
|
|
);
|
|
```
|
|
|
|
</RequestExample>
|