Using Webhooks to connect Maker with Twitter over IFTTT

With our new feature, you can publish a text on your Twitter account just by pressing the button!

 Intro

In this tutorial, you will be creating a rule that will enable you to send tweets just by clicking a button on your pinboard. To achieve this, the rule will use webhooks, which will in turn connect to IFTTT, which can be used to send messages to Twitter.

What are webhooks?

Webhooks provide a way for an internet platform to communicate with external APIs. In the case of AllThingsTalk Maker, webhooks are Rule Engine action components that, when triggered, send HTTP requests to a predefined URL. In our case, the triggering component will be a device with a virtual button, and the URL will be the one provided by IFTTT.

Prerequisites

  • FREE AllThingsTalk Maker account
  • Twitter account
  • IFTTT account
  • 15-30 minutes of your time
  • Some computing experience, but no previous experience with Maker or IFTTT
  • No physical device needed

Maker setup

We will start by setting up Maker with a device and a pinboard.

Create the device

As with any Maker project, we’ll start with creating a device in the Playground.
  1. If this is your first device, click on + CONNECT A DEVICE in the Devices pane. If you already have devices in the ground, click on + NEW DEVICE in the upper left.
  2. In the next screen, find the tile named “Your own device” and select it.
  3. Name the device “Magic Button” and click CONNECT.

Create the asset

Make sure that the asset you’re creating is virtual as shown below - you won’t be able to activate it from the pinboard otherwise.
  1. Click CREATE ASSET to get to “New asset” screen
  2. For Kind, select “Virtual”. Name your asset “Button”, and keep the type as Boolean. Then Click CREATE ASSET.

Create the control

To get a graphical control for you button that you will be able to click on, you will need to create a pinboard and pin the “Button” asset to it.
Create the pinboard
  1. Select PINBOARDS from the menu on the left.
  2. Click + CREATE PINBOARD and name your pinboard.
  3. Click ARRANGE PINBOARD
  4. Click on New pin to proceed with pinning the asset
 
Pin the control
  1. After clicking New pin, “Pin control” dialog will appear.
  2. From the list of available controls, choose “Push button”. Leave “Push to make” for type. Click NEXT.
  3. In the next screen, choose “Magic Button” as your device, and choose the “Button” asset. Click PIN.
  4. A cute red button will appear on your screen. Click SAVE.
If you would like to make the button larger, click on the cog on the upper right, select a larger size and click Save.

IFTTT Applet creation

On IFTTT side, we will need to create an applet. For the IF part, we will be using a webhook, and for the THEN part, we will send a message to Twitter.

IF This

First, we will create the webhook.
  1. Click your avatar on the upper right, and select Create
  2. Click on + This
  3. Use the search box to find “Webhooks”. Select the tile.
  4. Click on the blue “Receive a web request” tile
  5. Name the event “MagicButton” and select Create trigger.

THEN That

  1. Click on + That
  2. Use the search box to find “Twitter”. Select the tile.
  3. If you haven’t interfaced with twitter before, you will be asked to connect to it. After clicking Connect, there will be a pop up asking you to Authorize IFTTT to access your account. Click Authorize app.
  4. You will now get the opportunity to choose your Tweet’s text. Delete the preconfigured text, click Add ingredient, and select “Value1”. Value1 is one of the values that can be passed over the webhook. We are using it instead of hardcoded text in order to be able to change the text of the tweet on AllThingsTalk Maker. The dialog should look like the one above. Click Create action.
After this is done, you will be presented with a dialog to confirm your settings. Click Finish.

Obtain IFTTT webhook credentials

IFTTT will create a special preauthorized link that we can use with AllThingsTalk Rule Engine.
  1. Click your avatar on the upper right, and select My services
  2. Select Webhooks
  3. On the upper right, click Documentation
  4. You will be presented with a screen containing your key, and more importantly with the full link you will be using for the Webhook. In the image above, the key is blurred, as it should only be known to the service owner. You should keep yours secret too! Note that {event} is presented generically, and not set to “MakerButton”, so you will have to change it manually in the next step.
We suggest that you open Maker in another tab, so that you can more easily copy data, and if needed, switch between these two screens.

Rule setup

Now we’re getting to the exciting part! grinning face with big eyes
  1. Go to DEVICES panel, and select your device.
  2. On the upper right, click "+", and then click Create rule.
  3. You will be presented with the “Create rule” dialog, with “Magic Button” already added to triggers.
  4.  Check the “Button” checkbox, to use that asset and trigger the rule.
    Now, drag the webhook component from the left-hand side to ACTIONS, and populate the fields as shown.
    • Paste the link from IFTTT, and change “” to “MagicButton”.
    • Click + ADD HEADER, add “Content-Type” as the key, and “application/json” as value
    • In body, write {"value1": "Hello, World!"}. Remember, when we were setting up the applet, we specified that the text of the tweet will be contained inside "value1".
    • When done, recheck that you’ve entered everything correctly, and click CREATE RULE.
    For more info on the meaning of these fields, please consult Webhook documentation.

    Pushing the button

    Well done! With nothing else left to set up, we’re ready to push the button and say hello to the World. Navigate to the pinboard. There’s a button waiting to be pushed.
    Push the button. Check your twitter feed. Your message to the world should appear on the top.

    Outro

    You should pat yourself on the back. In this short time, you’ve managed to
    • Create a device
    • Pin a control
    • Setup IFTTT
    • Create a rule
    • Send a tweet by a pressing a single button!
     
    Here are some things that you could try to do now:
    • Order Domino’s by shaking your Microbit.
    • Link Maker with Google Sheets, and populate the table with data coming from your LoRa Weather Station.
    • Change a Hue light to red if the accelerometer detects that the pool table is in use.
    • Export your IoT data to data.world
    • Send a Slack message to your coworkers if the microphone detects that they are too loud.
    Have fun! winking face

    Related Articles