# Wait for Event

> Hold an automation until a specific event arrives, with an optional timeout and filter rule.

A **wait for event** step holds the automation until a specific event is received. Unlike a [delay](https://www.sendping.co/docs/automations/delay), which resumes after a fixed time, this step resumes when something happens in your application.

See [Using automations](https://www.sendping.co/docs/automations/overview) for the surrounding workflow.

Common use cases:

- **Payment** — wait for a payment to succeed before sending a receipt.
- **Adoption** — wait for a user to complete an action to unlock a feature.
- **Verification** — wait for the user to verify their email before continuing.

## How it works

Add a `wait_for_event` step to the `steps` array, naming the event to wait for and an optional `timeout`.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.automations.create({
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Automations.create({
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "verification",
      "type": "default"
    }
  ]
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->automations->create([
  'name' => "Verification reminder",
  'domain' => "yourdomain.com",
  'steps' => [
    [
      'key' => "start",
      'type' => "trigger",
      'config' => [
        'event_name' => "user.created"
      ]
    ],
    [
      'key' => "verification",
      'type' => "wait_for_event",
      'config' => [
        'event_name' => "email.verified",
        'timeout' => "1 day"
      ]
    ]
  ],
  'connections' => [
    [
      'from' => "start",
      'to' => "verification",
      'type' => "default"
    ]
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Automations.create({
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "verification",
      "type": "default"
    }
  ]
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

automation, err := client.Automations.Create(&sendping.CreateAutomationRequest{
    Name:   "Verification reminder",
    Domain: "yourdomain.com",
    Steps: []sendping.AutomationStepInput{
        {
            Key:    "start",
            Type:   "trigger",
            Config: map[string]any{"event_name": "user.created"},
        },
        {
            Key:  "verification",
            Type: "wait_for_event",
            Config: map[string]any{
                "event_name": "email.verified",
                "timeout":    "1 day",
            },
        },
    },
    Connections: []sendping.AutomationConnectionInput{
        {From: "start", To: "verification", Type: "default"},
    },
})
```

**Rust**

```rust
use sendping::{AutomationStepInput, ConnectionInput, CreateAutomationOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = CreateAutomationOptions::new("Verification reminder", "yourdomain.com")
    .with_step(AutomationStepInput::new("trigger")
        .with_key("start")
        .with_config(serde_json::json!({"event_name":"user.created"})))
    .with_step(AutomationStepInput::new("wait_for_event")
        .with_key("verification")
        .with_config(serde_json::json!({"event_name":"email.verified","timeout":"1 day"})))
    .with_connection(ConnectionInput::new("start", "verification").with_type("default"));
let _automation = mb.automations.create(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.AutomationConnection;
import co.sendping.requests.AutomationStep;
import co.sendping.requests.CreateAutomationRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

CreateAutomationRequest request = CreateAutomationRequest.builder()
        .name("Verification reminder")
        .domain("yourdomain.com")
        .step(AutomationStep.builder()
                .key("start")
                .type("trigger")
                .config("event_name", "user.created")
                .build())
        .step(AutomationStep.builder()
                .key("verification")
                .type("wait_for_event")
                .config("event_name", "email.verified")
                .config("timeout", "1 day")
                .build())
        .connection(AutomationConnection.of("start", "verification", "default"))
        .build();

SendPingResponse response = sendping.automations().create(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.AutomationCreateAsync(new AutomationCreateOptions
{
    Name = "Verification reminder",
    Domain = "yourdomain.com",
    Steps = new List<AutomationStepInput>
    {
        new()
        {
            Key = "start",
            Type = "trigger",
            Config = new Dictionary<string, object?>
            {
                ["event_name"] = "user.created",
            },
        },
        new()
        {
            Key = "verification",
            Type = "wait_for_event",
            Config = new Dictionary<string, object?>
            {
                ["event_name"] = "email.verified",
                ["timeout"] = "1 day",
            },
        },
    },
    Connections = new List<AutomationConnection>
    {
        new()
        {
            From = "start",
            To = "verification",
            Type = "default",
        },
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/automations' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Verification reminder",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "verification",
      "type": "wait_for_event",
      "config": {
        "event_name": "email.verified",
        "timeout": "1 day"
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "verification", "type": "default" }
  ]
}'
```

## Timeouts

When you set a `timeout`, the step stops waiting after that duration, which prevents automations from waiting indefinitely. A wait-for-event step produces two possible connection types so you can branch on whether the event arrived in time:

| Connection type | When it is used |
| --- | --- |
| `event_received` | The event arrived before the timeout. |
| `timeout` | The timeout elapsed without receiving the event. |

```json
{
  "key": "payment",
  "type": "wait_for_event",
  "config": {
    "event_name": "payment.completed",
    "timeout": "3 days"
  }
}
```

> **Warning:** The maximum timeout is **30 days**.

## Filter rules

Use `filter_rule` to match only events that meet specific criteria — useful when the same event name is sent with different payloads. The rule is evaluated against the incoming event's payload. For example, to wait specifically for a successful payment:

```json
{
  "key": "payment",
  "type": "wait_for_event",
  "config": {
    "event_name": "payment.completed",
    "filter_rule": {
      "type": "rule",
      "field": "event.status",
      "operator": "eq",
      "value": "succeeded"
    }
  }
}
```

The filter rule supports the same rule shapes and [operators](https://www.sendping.co/docs/automations/condition) as [condition](https://www.sendping.co/docs/automations/condition) steps — including `and`/`or` groups.

## Configuration

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `config.event_name` | string | Yes | The name of the event to wait for. |
| `config.timeout` | string | No | The maximum time to wait before timing out (e.g. `"3 days"`, `"1 hour"`). Maximum: 30 days. |
| `config.filter_rule` | object | No | An optional rule object to filter incoming events. Uses the same shape as a condition rule. |
