How to use Integromat to create automation workflows triggered by Bambuser content

In this guide we will look at how to react to incoming Bambuser broadcasts by listening to webhook events. We will use the cloud service Integromat to define an action to perform, such as posting to our WordPress blog or posting to a Slack channel.

First, sign up for Bambuser and Integromat. Bambuser has a free trial and Integromat has a free plan for low-volume use.

Create an Integromat scenario

In your Integromat account, create a new Scenario and add the Webhooks service as a starting point.

Integromat now gives us a public https url where Bambuser can post broadcast updates.

Send a sample broadcast to Integromat

To get some real-world data to work with, let's register this url as a listener on Bambuser dashboard's developer page.

Next, use Bambuser's mobile app in the App Store or Google Play or the go live button on the content page in Bambuser Dashboard, or any other broadcasting approach you prefer.

Titles are useful

Preferably set a title in your broadcasting tool of choice, as this can be a useful way to provide more context: the broadcast title can be reused as the blog post title and you can even take different actions based on the contents of it, more on that later.

A few seconds after you've started the broadcast, Integromat's scenario wizard will discover the structure of the webhook message which will help us a lot when creating the template for the blog posts or whatever we want to achieve.

A. Bambuser → Integromat → Wordpress

Creating one blog post per incoming broadcast could be quite useful - let's examine how Integromat can help us with that.

In the following section we will look at posting to WordPress. Integromat currently also has native support for Blogger, Tumblr and Medium.

Create a WordPress blog post template

In Integromat's scenario wizard, add the WordPress Create a post action as a second module and make sure it is linked to the Webhook module with a dotted line. In the first part of the Wordpress setup form, enter your blog url, username and password.

In the second part of the Wordpress form, create a post template. If you made sure to send a webhook event to Integromat already, they will show a menu of helpful placeholders that you can drag onto the form.

In most one-blog-post-per-broadcast scenarios, showing an embedded player is desireable. Let's use the basic iframe embed syntax in the Content field. When constructing the player url, you must urlencode the resourceUri, since it is essentially an url transported within an url. Fortunately, Integromat has an encodeURL function. We end up with something along the lines of:

<iframe src="https://dist.bambuser.net/player/?resourceUri={{encodeURL(1.payload.resourceUri)}}" style="border: none" allowfullscreen></iframe>

Remember to press the ok button in the form - if you accidentally close the form without pressing the button, the edits are lost!

As post title, let's use the broadcast title as suggested earlier. However, sometimes the title field is empty: some RTMP ingest tools and the WebRTC broadcaster does not expose a title field. And sometimes the user leaves the field blank. Integromat has a set of dynamic functions (available under the cogwheel button) and in this case ifempty is useful: it allows us to use the string "New broadcast" (or anything you prefer) as a fallback if the broadcaster did not provide a title:

{{ifempty(1.payload.title;"New broadcast")}}

Press the ok button, then save button, then activate the scenario, then test it again by creating a new broadcast.

You might notice that the posts show up as unpublished drafts. This is useful during testing. When you've fine-tuned your integration you can optionally set Status to Publish in Integromat's blog post template for a fully automated workflow.

React immediately

Integromat seems a little shy in reacting to events by default. Make sure you schedule it to run immediately on every incoming webhook request - and make sure to press both the ok button and the save button after making the change.

You might also want to set the tolerance for consecutive failures a bit higher tha the default: 3 while you're testing, if you experiment with changes that WordPress might reject: can be inconvenient to try 3 different incorrect states and wait for the 4:th to propagate only to realize after a While that Integromat has throttled itself...

React only to new broadcasts, ignoring updates

The broadcast webhook will fire multiple times for a typical broadcast. Most of the time you get an add event, followed by several update events each time something has changed significantly, whether an edit to the broadcast title or a significant geolocation change. Another common update is when a broadcast goes from being live to an archived replayable mode: the type field indicates this state.

For simple scenarios where we just want to react once per broadcast, we need to ignore all update events, otherwise our target system will be spammed with duplicates!

In Integromat's scenario wizard, click the dotted line between the Webhooks circle and the Wordpress circle, then select add filter. Choose action as condition and require it to have value add. Hereby, whenever action is update, the event will be silently dropped.

Whitelisting iframes in WordPress

By default, WordPress filters HTML tags quite aggressively. The iframe tag needed to embed a Bambuser player is not allowed unless you whitelist it.

This can be done by adding the following snippet to theme/functions.php or to a custom plugin.

Security

You should probably not enable this if you allow untrusted people to edit the blog posts on your site.

add_filter('wp_kses_allowed_html', 'allow_iframe_func', 10, 2);
function allow_iframe_func($allowedposttags, $context){
    $allowedposttags['iframe'] = array(
        'id'=> 1,
        'class'=> 1,
        'style' => 1,
        'src' => 1
    );
    return $allowedposttags;
}

In other words, this requires a WordPress host that allows you to edit your php files directly. On wordpress.com for example, a business plan is required.

B. Bambuser → Integromat → Slack

There is also a bunch of chat services available on Integromat. Let's look closer at Slack

Multiplexing

If you want to post to Wordpress and Slack in the same Scenario, then add a Router module to send the signal to both Slack and Wordpress. Make sure the ignore-updates filter is on the lefthand side of the router, so that both services get a filtered stream.

Slack posts and attachments

Then add the Slack action Post a new message as a new scenario module and set up a connection with the Slack environment you want to post to.

As title, let's use that title approach from the blog post again. Since Slack is more of a realtime tool than blog posting, let's add an indication in the default title of whether the broadcast was live or not when the post was made.

{{ifempty(1.payload.title; "new " + 1.payload.type + " broadcast")}}

Slack does not support arbitrary HTML and only video embeds from whitelisted services, but you can post a preview image and a link to the player. When constructing the player url, you must urlencode the resourceUri, since it is essentially an url transported within an url. Fortunately, Integromat has an encodeURL function. We end up with something along the lines of:

https://dist.bambuser.net/player/?autoplay=1&resourceUri={{encodeURL(1.payload.resourceUri) }}

(You reach the archived state straight away by uploading a video file via the mobile app or dashboard or via the api)

Slack has some basic formatting tools including a concept they call attachments and the Integromat module has support for this under its advanced settings.

Since we want to display an image and link to something, the attachment is a nice approach: it allows us to not display an image and some clickable text without having to display the underlying urls.

If we create an attachment and provide Title, Title link, Image and Fallback as well as a couple of custom fields, we should get something like this over in our Slack channel when we do our next broadcast:

Alternatives

Close to what you need, but don't like Integromat's scenario editor? Also check out our Zapier guide.

Need even more control? You can also emit the webhook events to your own server or to a Google Cloud- or AWS-hosted cloud function and react with custom code.