Files
2023-08-14 22:04:40 +01:00

56 lines
1.2 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 code 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.
## 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>