API Development

Integrating Axway Application Integration: Automating the use of Twitter Tweets with Hashtags

automating use of Twitter Tweets with Hashtags

This blog entry is part of a two-part series where we will ultimately build a Cloud to Cloud (C2C) integration between Twitter and Slack, utilizing a Scheduled trigger to execute an automated orchestration Flow.

In this blog entry, I will cover how to:

  1. Create a Scheduled Trigger Flow in Axway Integration Builder (IB).
  2. Set the Trigger to check periodically for Tweets with a specific hashtag.
  3. Create a Flow Instance to execute successfully and monitor the steps configured in the Flow.

Prerequisite Reading

This ain’t our first rodeo! Not every step is explicitly covered here if we have done it elsewhere before. Check out these two blogs to fill in the pieces where mentioned in the below steps.

Integrating Axway Application Integration and Slack by Daniel Wille

Axway Integration Builder—Scheduled Triggered Flow Example by Leor Brenman.

Create and Configure and Event-Based Flow

At this point, we have seen how the Twitter APIs can be used to see statuses with a specific hashtag. Next, we can see how to set up a Scheduled Trigger to poll automatically Twitter on a schedule and capture new Tweets using that hashtag.

  • Log in to the Axway Platform and navigate to the IB Sandbox. Navigate to the Flows tab on the left-hand side. Select “Build New Flow Template.”
Build New Flow Template
  • Choose “Build a New Flow,” choose a unique name, and choose a Scheduled Flow. This type of Trigger will operate against the cronjob configured, in this case, to call the REST API associated Connector Instance. We will set the variable up as part of the trigger creation to store the cron expression to maximize the flexibility of the template. Click the “ADD SCHEDULED” button to get started. When prompted for the cron expression, choose a variable (e.g. cron) to be populated later. Click Save.

  • This should bring you to the Flow builder page. We need to start by setting a variable for our Twitter and our Slack instance. Choose to create a new Variable in the top right of the screen. Choose “Connector Instance.” Name this variable something that will represent your Slack Connector Instance (e.g. dwslack01). Do the same for a Twitter variable.

  • Create a Value type Variable named “cron” (which we referred to earlier and is invoked as config.cron). This will represent your cron expression as mentioned in the earlier step when creating the Trigger. By making this a variable, we can easily update it as desired when creating or updating a Flow Instance.
Flow Variables
  • Create Value type Variable named “slackChannel.” This will represent your Slack channelID that we tested in the last blog. By making this a variable, we can easily update it when creating a new Flow Instance to tie easily into many Slack channels.

  • At the end of this step, your Variables page should show two Connector Instance variables, which we will later link to our Twitter and Slack Connector Instances, and two Value variables, which we will populate later with our cron expression and our Slack channel ID.

  • Press the Plus button in the Flow field to add your first step. Choose Connector API Request. Here we will set the callout to Twitter whenever the cron executes to return statuses with our selected hashtag. In this demo, I hard code the hashtag value for ease of use. To improve upon it, however, you could use another value Variable so it is configurable when you create your Flow Instance. Note the URL encoding of the special character within the single quotes of the Where query. Just as with the REST APIs tested in the last blog, the Where query must be present. Your configuration should look similar to mine below:

  • Once this is saved, click on the step and select “OnSuccess” to choose your next step. Select a JS Script step. The name of this step will be used in a variable name in the next step, so I suggest using something easy with no spaces (e.g. preparePostToSlack).
    • Create a variable to represent the body and return it with JavaScript. For this demo, I have updated the Slack field to use a variable from the previous step. This will return the “text” field first result from calling the Twitter API. The idea is for my Slack channel to get periodical updates on what may be happening with regards to Earthquakes around the world, but make it short and easily consumable.

JS Script Contents

let body = {“text”:'”‘+steps.CallTwitter.response.body[0].text+'”‘};

done({body:body});

  • Check your JS Script filter looks similar to the screenshot below. If so, save and continue.

  • Click on the JS Script filter you created and choose “On Success” to add the next step. Choose Connector API Request. Fill it out as follows:
    • Name: WhateverYouWant (e.g. POSTtoSlack)
    • Connector Instance Variable: Press plus and choose the slack variable you set earlier (e.g. swslack01).
    • Method: POST
    • API: /channels/${config.slackChannel}/messages. Replace the channelID with the id you captured in the last blog post when testing your Slack APIs.
    • Choose “Show Advanced.” In the body field, refer to the body variable you set in the previous step. The name of the step will change based on what you called that step (e.g. ${steps.preparePostToSlack.body}).
  • Save this and navigate back to Flows by clicking on the Flows tab to the left. Find your new Flow. Hover over it and choose “Create Instance.”

  • Configure the Flow Instance.
    • Select the plus in the Twitter variable box. Select your Twitter Connector Instance we set up in the first blog post.
    • Select the plus in the Slack variable box. Select your Slack Connector Instance.
    • Fill in the cron variable in the Values box. This uses Quartz Cron Expressions, which Leor details more in his post covered in the prereading. My sample cron here executes once per minute.
    • Fill in the slackChannel variable in the Values box with your Slack ChannelID.
    • Choose create Instance.

Demonstrate the Flow in action.

  • Navigate to your Flow Instance in Axway Integration Builder. This can be done by clicking on the “Flows” tab, searching for your Flow Template, then selecting the number on it to see your Flow Instances. Hover over it and select “Executions.” Recall we set the Scheduled Trigger cron to execute everyone’s minute. Refresh until you have seen the execution as “Pending” in yellow. A few seconds later, refresh again and you should see success in green.

  • Check your Slack channel once a minute for new updates on Earthquake news around the world, powered by Twitter.

Conclusion

At this point, you should have a working Cloud to Cloud integration between Twitter and Slack with an automated Flow Instance that kicks off a Scheduled execution of the Twitter statuses API once per minute. This Flow checks for hashtags as defined in the Connector API Call step, and relays them to an endpoint, in this case, a Slack channel.

The Flow Template is completely reusable. Just create a new Flow Instance where you can modify the Slack or Twitter instances you are connected to, or the Slack Channel or cron. This could also be updated to allow for a variable for the hashtag. Perhaps one also wants to watch for floods, hurricanes or tornados!

What Now?

From here there are many ways you could use this base demo.

  • You might update the message body sent to Slack with more details on the incident.
  • You may wish to change it to watch for statuses that involve your enterprise being mentioned on Twitter for real-time alerting.
  • You might want to leverage the Twitter APIs in new in different ways—perhaps publishing content automatically or automatically following those who follow you.

The possibilities are endless!

Enjoy this blog post? Follow me on the Axway Devblog. Stay tuned, enjoy and reach out if you have any questions, comments or concerns with this configuration!

Want to know more about Axway Integration Builder and the art of the possible? Let us know by going to our site and clicking the “CONTACT” tab in red on the right.