You can use Flock's webhooks to send and receive messages from external services using JSON packets. An incoming webhook posts messages to a Flock channel from an external service.
Create an incoming webhook
- Navigate to the Flock Developer Dashboard at https://dev.flock.com.
- Sign in with your Flock account and click Webhooks on the left.
image-shadow |
- Choose to Add an Incoming Webhook.
- Select the Channel where you want incoming messages to be posted.
image-shadow |
- Give the webhook a name and an icon that will be used to post messages in Flock.
image-shadow |
- Click Save and Generate URL. Copy the URL that is generated.
- This is the webhook endpoint and it accepts JSON packets posted to it. The following command will post a message "This is a test message" to your configured channel:
code-block | bash |
|
Transforming JSON payload formats
Flock's incoming webhooks support Message objects with two common attributes or keys - "text" for message content and "flockml" for message formatting.
code-block | bash |
|
OR
code-block | bash |
|
Some external apps and services may send data that does not follow Flock's JSON payload format, and hence it is not parsed.
In the following example, the JSON payload received is not in a compatible format, so no message is generated:
code-block | bash |
|
To receive messages via an incoming webhook from an app and service that uses an incompatible JSON format, you'll need to transform the data into a Flock-compatible format.
- First, make a note of the keys and values in the JSON payload.
- In the above example, the attributes are "product", "units", "customer", and "price" with the corresponding values being "iPhone", "1", "Adam", and "1000".
- Convert all the incompatible attributes to placeholder keys in the format: $(json.attribute)
- These placeholder keys will be replaced by the corresponding values in the message.
- String together the placeholder keys into an English sentence, and assign it to a key "text" or "flockml".
- Here is an example of the transformation template for the incompatible JSON payload:
code-block | bash |
|
- Go to your existing incoming webhook, click Edit and paste the transformation template under Template Heading.
image-shadow |
- The webhook will now generate messages in Flock such as "Adam bought 1 iPhone @ $1000".
alert-warning | The number of webhooks that can be created as per the current standard is 10 per user. |