# User guide

## Setting up a new webhook in a chat room

1. First, add the Universal Webhook bot into the chat room, by clicking **Add members** at the top of the chat room, then searching for **Universal Webhook**.&#x20;

{% hint style="info" %}
**Notes**:&#x20;

* The bot may be named differently, in that case please contact your admin to have the right name.
* The bot needs permission to send messages in the chat. If your chat is configured to prevent members from posting messages, then promote the bot as chat owner instead.
  {% endhint %}

2. Once the bot is in the chat, **click on the Universal Webhook button** that appeared in the header of the chat room, as visible below:&#x20;

<figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2F4s1v7uuRwAyeyfbc6fYA%2Fimage.png?alt=media&#x26;token=0a66a63e-b143-4c13-8e49-6ad2ceac6575" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you don't see the button in the chat header please check the following:

* You need to be an **owner** of the chat to configure a webhook.&#x20;
* You may not be entitled to the Universal webhook **app** - Check the Marketplace to see if the app is installed for you.
* Confirm with your admin that you added the **right bot** to the chat - It may be named differently than 'Universal Webhook'
  {% endhint %}

3. A modal window opens that lists the webhooks already configured for this chat. Now, select **Add a webhook**.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FJjx3BQFCUHjsyCi7dE7I%2Fimage.png?alt=media&#x26;token=dcd09e70-3036-4584-b824-ed93f6f82cd8" alt=""><figcaption></figcaption></figure></div>

4. Add a **name** for your webhook. Anything will do - this is so you can identify the webhook later.&#x20;
5. In the **Integrated service** field, indicate which service will be sending data to Symphony Messaging.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FjSBKtXjJjNB0hMiupAq2%2Fimage.png?alt=media&#x26;token=8b180136-b2cc-4f7b-9ef0-93d92be65e40" alt=""><figcaption></figcaption></figure></div>

6. Select whether the service will send Raw Text, MessageML v2 (Symphony Messaging's markup language), or a JSON object in the **Webhook type** field.&#x20;

You can find the specifications of the MessageML v2 under the following link: [MessageML v2 Specifications](https://docs.developers.symphony.com/building-bots-on-symphony/messages/overview-of-messageml).

Also, note that your webhooks can contain attachments for any type you choose. This particular case is addressed at the end of this page.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FAhEhee3gg8gDo1UNyfau%2Fimage.png?alt=media&#x26;token=9edf7159-4519-482e-b33c-61887b59ef0e" alt=""><figcaption></figcaption></figure></div>

### Testing a JSON mapping

If your service sends a JSON object, you will need to provide a template for mapping the JSON data to a readable format.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FSERSmhiUZl2VNUIRoeXV%2Fimage.png?alt=media&#x26;token=08131d88-f1c8-47c2-aa5a-162fbe8949d7" alt=""><figcaption></figcaption></figure></div>

1. Enter your template and a sample of JSON data.
2. Click **Test** to see how your message will render.&#x20;

If your message is valid, the bot will send you the message in a direct chat. If not, an error message will advise you why your template or data is not valid.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FhhYdSEdNMiZyyBnlvrA7%2Fimage.png?alt=media&#x26;token=f13d64d4-cd92-444a-8929-6c3e2948d6e3" alt=""><figcaption></figcaption></figure></div>

## Authentication

### Unauthenticated webhooks

&#x20;In the **Security type** field, you can choose the security protocol that validates the incoming data.

If your Symphony Messaging Admin has permitted it, you will have an option for Unauthenticated Webhooks. In this case, incoming data will not be validated.

Symphony recommends using a security protocol to validate the data, even if you are not required to do so.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2Fj0D7vt8fwqDYcFqYiRAA%2Fimage.png?alt=media&#x26;token=cb68aeb2-38d1-4a1d-a58e-8b048edaefcb" alt=""><figcaption></figcaption></figure></div>

### Shared Secret authentication

If you choose 'Shared Secret,' your data will require a secret to be sent along with it under a custom header.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2Fh39faLFfGe8PxOELsldo%2Fimage.png?alt=media&#x26;token=31481d84-be6c-4186-abd1-b2c0e53a99d8" alt=""><figcaption></figcaption></figure></div>

1. Choose a **custom header** for your webhook. Any data sent without this header will be rejected.
2. Enter a **secret value**. Universal Webhook will match this value with the value under the header you chose above to validate your webhook data.

### HMAC Secret authentication

If you choose 'HMAC Secret,' your data will require a secret to be sent along with it under a custom header. The value of the secret header will however be a hash that will be depend both on the content of the payload as well as on the pre-configured secret.

More precisely, Universal Webhook will use the HMAC SHA256 algorithm to compute a hash from the payload of your message and the secret key. Then it will match the result with the value of the custom header received in the webhook, which you will have also computed before sending in a similar way.&#x20;

If the values don't match, then the data will be rejected.

<figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2F8nAZ5YX2iMcgkdxTiAYr%2Fimage.png?alt=media&#x26;token=a198ce1a-27e9-40ff-a108-b0db3b4d32e8" alt=""><figcaption></figcaption></figure>

1. Choose a **custom header** to use for your webhook. The custom header name needs to be <mark style="color:red;">**lower case only**</mark>. Any data sent without this header will be rejected. Let's use `"authorisation"` for our example.
2. Enter a **secret value**. Let's use `"this is my secret"`
3. Build the text to be hashed: Take the value of the `message` property, remove the `<messageML>` tags, then wrap it in a JSON payload property:
   * For example message `<messageML>Hello world!</messageML>` would become `{"payload":{"message":"Hello world!"}}`
4. Using the HMAC SHA256 hash function, compute a hash of the text above using the secret `"this is my secret"` as secret key.
   * Using the sample secret defined above, you should obtain the following hash `8de567399a49f3ed91ed55435c0887c7c935413e01cbd7a2ac06dab1b04cc1c6`
5. Send the request to the webhook URL and specify in the http headers the custom header and the computed hash as value:&#x20;
6.

```
<figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FkeaDw4hjfYz37ld21h9f%2Fimage.png?alt=media&#x26;token=8d6d20da-bcf0-491a-bb9d-a2a64ee991f8" alt=""><figcaption><p>Example in Postman</p></figcaption></figure>
```

7. Universal Webhook will perform the same steps, compute the hash and compare it with the provided hash. If the values match, the message will be sent in the chat room.

## Integrating with your service

1. Click **Save and activate** to create your webhook.
2. **Copy** the provided URL and enter it where it is needed in your service's settings.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FtTkDRNxCUbKdVuIkHLKY%2Fimage.png?alt=media&#x26;token=db059290-4734-483a-be71-0e179c4ea902" alt=""><figcaption></figcaption></figure></div>

## Example with Postman

Consider this sample setup using Shared Secret validation.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FPLmFj7ib8KWsWqUb1TuQ%2Fimage.png?alt=media&#x26;token=a1c5cd29-ff4a-4160-b270-c3e2b08d6afa" alt=""><figcaption></figcaption></figure></div>

1. Fill in the fields and click **Save and Activate**.
2. **Copy** the generated URI to provide to the service that will send data to the webhook.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FGxxE4IKmayQD0cMyqwFj%2Fimage.png?alt=media&#x26;token=182fd02c-c58b-4397-87dd-9da1485d1134" alt=""><figcaption></figcaption></figure></div>

3. In Postman, create a new POST method and paste in the URI.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FG47q7mEy1Tm77sokc04L%2Fimage.png?alt=media&#x26;token=da22b88c-65e7-4b46-bd4a-1f069891969a" alt=""><figcaption></figcaption></figure></div>

4. In the Headers, enter the Shared Secret Header and the Secret to match the values from the webhook setup.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FXEiipGG3wziH5kVwM9MF%2Fimage.png?alt=media&#x26;token=91a38dc2-a0c9-4e41-9456-9c4ed6c7aa8b" alt=""><figcaption></figcaption></figure></div>

5. In the Body, enter a raw text or MessageML v2 message to send, then click the **Send** button.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FZwLCvwQO62ieijOQKAyt%2Fimage.png?alt=media&#x26;token=9e301dcb-6b98-46c5-a920-018110d26571" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FN1mo0hLqkyHv3NqfpsBw%2Fimage.png?alt=media&#x26;token=406885be-9445-4d72-a161-bb9fb70e525f" alt=""><figcaption></figcaption></figure></div>

After a moment, you should see a '200 OK' success indicator in Postman.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FKnxDqLmuljeM7ybppLpn%2Fimage.png?alt=media&#x26;token=fd6a7be5-3a7f-4f22-8fb3-7480a844bd92" alt=""><figcaption></figcaption></figure></div>

And in Symphony Messaging, Universal Webhook delivers your message.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FXIQvloy31eMt5yekG5WO%2Fimage.png?alt=media&#x26;token=729d3ea0-9807-493b-b7b1-9c848c138ba1" alt=""><figcaption></figcaption></figure></div>

## View your webhooks

Now, when you open the Universal Webhook Modal, all of the webhooks for the room will appear in a list.

From this list, you can deactivate, edit, or delete a webhook. Webhooks must be activated in order to work.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2Fsntc6NgNZ5ETDPCqgZmm%2Fimage.png?alt=media&#x26;token=e6575bca-62c3-43f5-bc45-cc2b9f4af90a" alt=""><figcaption></figcaption></figure></div>

If you hover over the webhook name, an icon will appear.&#x20;

* Click this icon to copy the webhook URL to your clipboard.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FCduOsz3zQhhdLdDHMvx3%2Fimage.png?alt=media&#x26;token=fcc2c5a8-26f0-4157-842c-2db03d4a8744" alt=""><figcaption></figcaption></figure></div>

* Click the webhook name to show the webhook history.

### View your webhook history

The webhook history view shows a high-level view of your webhook information, but doesn't expose your security secrets.

You are able to see all accepted and rejected requests over the last month. Filters will allow you to limit which requests you see.

* Click any item in the list of requests to expand it so you can see more information.
* Click the item again to collapse.

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FlrTRyoMFKlimgaIvgS4K%2Fimage.png?alt=media&#x26;token=f9d00e5f-11d2-4320-b5d7-f2fecbd7918e" alt=""><figcaption></figcaption></figure></div>

## Send attachments in Symphony Messaging

To attach files to a webhook, set the`Content-Type` header to `multipart/form-data` and add the attachments in the`attachment` field.\
You can also include a preview of the files that will be displayed directly in the chat conversation, using the `preview` field.

The way to attach files depends on the type of webhook used (MessageML v2, Raw text, or JSON). An example of each type is available below.

**MessageML example**

Example of a MessageML webhook with a file attached, in Postman.&#x20;

<figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FC1er1SE1MykRJKSBRUvj%2Fimage.png?alt=media&#x26;token=67b41ed4-46a5-442d-8def-f6e70c16f69a" alt=""><figcaption></figcaption></figure>

**Raw text example**

Despite the webhook being of type Raw text, please continue to set the content type to `multipart/form-data`, as you can see in the following example.

<figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FLVsv5VZYikB7rt2VViui%2Fimage.png?alt=media&#x26;token=f2154d5f-b97f-4bed-a4d9-97937ec927ee" alt=""><figcaption></figcaption></figure>

**JSON example**

With a JSON webhook, the message data needs to be added to the `data` field.&#x20;

Example in Postman:

<figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FkJim7kEycL0ocn68IsTg%2Fimage.png?alt=media&#x26;token=af5d5e53-45b4-4f9b-a89e-12cb74efd372" alt=""><figcaption></figcaption></figure>

Example in cURL:

```
curl --location 'https://corporate.symphony.com/universal-webhook/041daxxxxxxxc4eXYZ' \
--header 'secret: thisismysecret' \
--form 'data="{\"mydata\":\"This is a message\"}"' \
--form 'attachment=@"/C:/Users/pierre.neu/Downloads/image (19).png"'
```

Corresponding JSON template:

```xml

<messageML>
  ${entity['mydata']}
</messageML>
```

### Adding preview of the files

Postman request sample of MessageML v2 type with an attachment and its preview:

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2F6FGkjQaBi7pCCTXx2eCd%2Fimage.png?alt=media&#x26;token=fc5f91e8-c3bc-4780-bcdc-23f91e6a451b" alt=""><figcaption></figcaption></figure></div>

Display of the resulting message in a chat:

<div align="left"><figure><img src="https://3121587452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB51RkjSmfA_ejydg4M-3415978100%2Fuploads%2FCeUmJyQlwHa0cdqskIJ6%2Fimage.png?alt=media&#x26;token=25405947-17e6-42dc-8984-6881ef8ab047" alt=""><figcaption></figcaption></figure></div>

### **Limits of attachments**

Attachments are subject to the following limits:

* Max size of 25Mb;&#x20;
* It is recommended not to exceed 25 files;&#x20;
* It is possible to use a preview with the attachment; please note that an error will be returned if the number of previews doesn't match the number of attachments if any preview is present in a webhook;&#x20;
* You might get an error if you try to send attachments which type is not supported by your pod.
