Build

SMS Notification System with PubNub and IFTTT

7 min read Markus Kohler on Mar 14, 2024

If you are a developer, you have most likely heard about concepts such as IaaS (Infrastructure as a Service), PaaS (Platform as a Service), and SaaS (Software as a Service). These concepts are crucial in building, managing and deploying applications and services. IaaS provides you with scalable computing resources over the Internet. PaaS offers a platform that allows developers to develop, run, and manage applications without the complexity of building and maintaining the underlying infrastructure. SaaS also delivers software applications over the Internet. Services, such as IFTTT (If This Then That), a SaaS platform and PubNub, an IaaS platform, provide valuable tools for automation and real-time communication, allowing you to get your application to production faster than ever.

Technical Overview

PubNub Event & Actions (E&A)

PubNub Events & Actions (E&A) is an extension of the PubNub Platform. PubNub Events & Actions enables you to filter/process your own PubNub Events and send these events to third-party services that you may have set up in multiple ways. 

PubNub Events can be generated when a user publishes a message, changes to the user's presence state, or a number of other events (see our Event documentation for a full list). PubNub events are then picked up by a PubNub Events Listener. The PubNub listener listens for a specific event and fires a corresponding action. This process is done directly on the PubNub Portal with zero coding.

IFTTT and SMS Notifications

IFTTT is a web-based automation platform that enables users to connect different web applications and services to automate tasks and discover new functionalities. It helps create simple, conditional statements known as applets, which changes in applications or services can trigger.

Two of the 100+ integrations you can set up through IFTTT are a Webhook and SMS Notifications. These integrations will be connecting to PubNub Events & Actions (E&A). The diagram below will help visualize the system we will be creating.

Prerequisites

Ensure you are signed up for a PubNub Account, and check out the Events & Actions Pricing page for cost details. You can also navigate to Events & Actions within the Pubnub Admin Portal and select “Upgrade” to view the pricing plans for Events & Actions. We will use the PubNub Debug console for this blog to publish messages and process them using IFTTT.

Make sure you signed up for an IFTTT account, as we will be using that to set up the SMS integration and connect to it via a WebHook, as seen in the diagram above. 

To read more about getting started and more advanced details on E&A, be sure to read some of our other content regarding PubNub Events & Actions:

Connecting PubNub with IFTTT

Refer to our docs for more detailed information on setting up PubNub with IFTTT.

In this walkthrough, we will use the PubNub Events & Actions IFTTT integration and connect our PubNub instance directly to IFTTT. We will automate SMS notifications to your phone when a message is sent through a specific channel.

First, let's create an Event Listener within the PubNub portal. This event listener will be responsible for listening for messages sent through the channel “Send_SMS.”

The configuration below shows how to set up a basic filter to listen to messages sent through the channel “Send_SMS.” However, there is much more you can do with PubNub Events Filters when using the Advanced JSON Path feature.

Now that we have configured the Event Filter, we can attach our PubNub Action. The Event Name will be used later when setting up the IFTTT environment. We will also grab the IFTTT Webhook key and set up our IFTTT workflow.  Additionally, you can add headers to the Webhook request; this is not required to connect PubNub to IFTTT.

After adding the PubNub Action, head to IFTTT, click Create and select “If This.” In the search bar, search for “Webhook”. We will use the “Receive a web request with a JSON payload” option, as seen in the image below.

Enter the “Event Name” from the PubNub Action we have set up, which is, in this case, “publish_message.” The event name has to be the same between PubNub and IFTTT. After creating your “If This” trigger, grab the Webhook key, navigate to the Webhook Service Page, click on documentation and copy your Webhook key from there.

For the “Then That” trigger, search for “SMS” and create that Action. We will now add some “Filter Code” to the workflow to parse the PubNub Event and send only the message portion.

Refer to the PubNub Event below to understand everything contained within a published event. We are going to use the parse the message out of it.

The filter code below parses the PubNub Event and sends the “message” portion as a text message.

The finished Applet and PubNub integration should now listen for a published event from PubNub through the channel “Send_SMS,” and parse the PubNub Event on the IFTTT side and send the SMS messages to your phone number.

Developer Use-Cases

Let’s dive into some use cases to see PubNub with an IFTTT integration in a real-world scenario.

Chat Applications

A company uses a chat application for internal communication among its employees. They want to improve their internal support system for IT issues. The goal is to automate the creation of support tickets from chat messages and notify the relevant IT support staff in real-time.

Chat Application with PubNub: The internal chat application uses PubNub for real-time messaging. Each department has its chat channel, including the IT support channel.

IFTTT Integration: The chat application is integrated with IFTTT using PubNub Events & Actions. The integration is set up so that specific keywords or phrases typed in any departmental chat channel can trigger actions outside the chat app.

Trigger Setup: In the chat application, an employee can report an IT issue by sending a message with specific keywords, such as "IT issue," followed by a brief description of the problem. PubNub detects this message in real time and triggers a predefined IFTTT applet.

IFTTT Applet for Ticket Creation: The triggered IFTTT applet is configured to create a new support ticket in the company’s ticketing system (e.g., Jira, Zendesk). The applet extracts the message content and uses it to fill in the details of the new support ticket.

Notification to IT Support Staff: Once the support ticket is created, another IFTTT applet is triggered to notify the IT support staff. This can be done through various channels supported by IFTTT, such as sending an SMS or an email or even posting a message directly in the IT support's chat channel in the chat app.

Confirmation Message: A confirmation message is sent back to the original chat channel where the issue was reported, acknowledging that the ticket has been created and that the IT support team has been notified. This message can include the ticket ID for reference.

IoT Device Monitoring

A company has an array of IoT devices (e.g., environmental sensors, smart meters, security cameras) deployed for various operational purposes. These devices are connected and communicate through PubNub, allowing real-time data transmission and monitoring. The company utilizes a chat application powered by PubNub for internal communications. The integration with IFTTT enables the company to automate responses or notifications based on the data received from the IoT devices.

Real-Time Data Transmission: Each IoT device is configured to publish its status updates and alerts directly to a dedicated PubNub channel. These messages can include various data types, such as temperature anomalies, battery levels, or unauthorized access alerts.

PubNub Function for Data Processing: A PubNub Function is deployed to filter and process data from IoT devices in real-time. This function can evaluate the incoming messages for specific conditions or thresholds that indicate urgent attention is needed (e.g., a sensor detecting a temperature outside a predefined range).

IFTTT Integration for Automated Actions: When the PubNub Event Listener detects an alert condition, it triggers an IFTTT event through an IFTTT Webhook. This event is configured to perform automated actions, which might include:

  • Sending an email or SMS to specific personnel or external contractors responsible for managing the IoT device in question.

  • Creating a new Support Ticket in the company's Ticket System (e.g., Jira). The applet knows what is wrong with the IT device from the message alert and can report the log file for the IOT directly inside the ticket.

  • Logging the event in a maintenance log for future analysis and action.

IFTTT Applets for Device Control Commands: The chat application allows team members to send commands back through PubNub to the IoT devices to perform immediate actions (e.g., reset the device, adjust settings) based on predefined applets in IFTTT that respond to specific keywords or commands posted in the chat.

Getting started with PubNub

We have just described how to use the IFTTT action and set up a simple PubNub Event Listener. To expand on using PubNub Events & Action, check out some other actions that PubNub provides.

PubNub provides a wide set of SDKs to integrate these actions into your applications. These SDKs facilitate the implementation of PubNub's capabilities into your current applications, making it straightforward to add real-time data streaming, processing, and communication features. Whether working with web, mobile, or server-side applications, PubNub's SDKs offer the tools you need to build highly interactive and responsive applications.

Feel free to contact the developer relations team at devrel@pubnub.com with any questions or concerns.