# OneSignal

## Integrating ContextSDK Push Notifications with OneSignal Journeys

This guide provides step-by-step instructions on how to configure [OneSignal's Journeys](https://documentation.onesignal.com/docs/journeys-overview) to send push notifications using a webhook to interact with the ContextPush API.

### Step 1: Add a Webhook Action to the Journey

1. Go to the **Journey** you want to leverage context-aware push notifications.
2. **Add a new action** within your journey by selecting "Add Action" and then choose "Send Webhook."
3. **Configure the webhook** with the following details:
   * **URL**: `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user`
   * **Request Type**: `POST`

### Step 2: Set Up Request Headers

In the webhook configuration, include the necessary headers to authenticate the request:

* **Authorization**: `Token [Your_Token]`
* **Content-Type**: `application/json`

<figure><img src="/files/grvsGloSbwHeO6yH9I2E" alt="" width="375"><figcaption></figcaption></figure>

### Step 3: Define the Request Body

Configure the webhook payload using OneSignal's templating to dynamically include user-specific data. Use the following JSON structure:

```json
{
  "bundle_id": "com.contextsdk.demo",
  "platform": "ios",
  "user_id": "{{ user.external_id }}",
  "content": {
    "title": "It's time to get started with crypto",
    "body": "Just upload your ID, and start trading now"
  },
  "deliver_within_hours": 6,
  "campaign_id": "daily-reminder",
  "delivery_method": "context_aware"
}
```

**Notes:**

* Replace `{{ user.external_id }}` with the appropriate OneSignal variable for the user ID.
* Adjust the `title` and `body` fields to match your campaign's messaging.

#### Using the Key/Value Pairs Body

If you prefer configuring your payload purely through the OneSignal UI we have a special endpoint that is compatible with a non nested JSON body. Instead of `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user` use the `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user_flattened` endpoint. This allows you to replace all nested values with keys in the format of `content/title`, `content/body`, etc.

This way you can fully configure ContextPush using only Key/Value pairs.

```json
{
  "bundle_id": "com.contextsdk.demo",
  "platform": "ios",
  "user_id": "{{ user.external_id }}",
  "content/title": "It's time to get started with crypto",
  "content/body": "Just upload your ID, and start trading now",
  "deliver_within_hours": 6,
  "campaign_id": "daily-reminder",
  "delivery_method": "context_aware"
}
```

<figure><img src="/files/upkLGTbRwHJa9q6kDqar" alt="" width="375"><figcaption></figcaption></figure>

#### Localization

You can use the built-in Liquid syntax to directly supply the localized string when scehduling a message. The below example uses the `https://push.contextsdk.com/v1/campaigns/schedule_message_for_user_flattened` endpoint:

```json
{%- assign userLang = user.language -%}
{
  "bundle_id": "com.contextsdk.internal",
  "platform": "ios",
  "user_id": "{{ user.external_id }}",
  "content/default_locale": "en",
  "content/title/en": "{% if userLang == 'de' -%} James, es ist Zeit für deinen Englischkurs! {%- else -%} James, it's time for your english course! {%- endif %}",
  "content/body/en": "{% if userLang == 'de' -%} Starte jetzt mit deinem Kurs! {%- else -%} Start course now because its a good time! {%- endif %}",
  "deliver_within_hours": 3,
  "campaign_id": "daily-reminder",
  "delivery_method": "context_aware"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.contextsdk.com/context-push/push-notification-providers/onesignal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
