SMS Notification System with PubNub and IFTTT
Published: 2024-03-14 16:11:05

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)](https://www.pubnub.com/solutions/enterprise-software/). 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](https://www.pubnub.com/docs/serverless/events-and-actions/overview) (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](https://www.pubnub.com/docs/serverless/events-and-actions/events) 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](https://ifttt.com/) 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.

![](https://www.pubnub.com/cdn/3prze68gbwl1/1IXhfT1ibiNjXbPOhJAAyn/57dc31be82227fe229993d7bdd1afd4f/Frame_1.png)

Prerequisites
-------------

Ensure you are signed up for a PubNub Account, and check out the [Events & Actions Pricing](https://www.pubnub.com/docs/general/resources/events-and-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:

-   [Setting up Events & Actions](https://www.pubnub.com/how-to/set-up-events-and-actions/)
    
-   [Difference between E&A and Functions](http://pubnub.com/blog/events-and-actions-or-pubnub-functions-picking-the-right-tool/)
    
-   [How-to filter messages using Advanced JSONPath](https://www.pubnub.com/how-to/eanda-advanced-jsonpath-filter/)
    

Connecting PubNub with IFTTT
----------------------------

Refer to our [docs](https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-ifttt-action) 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.”

![](https://www.pubnub.com/cdn/3prze68gbwl1/cqscJ3G6ji9oVY84zLmfC/a4874dcaa52203e484cde8370ee66006/Screenshot_2024-03-11_at_12.51.17_AM.png)

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.

![](https://www.pubnub.com/cdn/3prze68gbwl1/6rQ3JLm967DVo6FcLkyfgN/f9db88a18de625133c2e8d16f36e0a88/Screenshot_2024-03-11_at_12.50.55_AM.png)

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.

![](https://www.pubnub.com/cdn/3prze68gbwl1/707m0doUUFo4vXgIPGrq1s/254983405bb2d2cf73e8285d2ff12869/Screenshot_2024-03-13_at_9.42.27_PM.png)

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.

![](https://www.pubnub.com/cdn/3prze68gbwl1/3zSQLTPtmqAnirqNxo2Omn/eae7a7d6a85f48a7e08e75e3deb82407/Screenshot_2024-03-13_at_10.32.44_PM.png)

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](https://ifttt.com/maker_webhooks), 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.

![](https://www.pubnub.com/cdn/3prze68gbwl1/6LQGoclDVwVXGyeJiSylmD/998ed40b1fa206d40d73cf6f5a233516/Screenshot_2024-03-13_at_10.46.47_PM.png)

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.

```js
{
  "event": {
    "channel": "Channel-Barcelona",
    "eventCategory": "message",
    "eventType": "message.publish",
    "eventId": "8997eeb6-2a94-455b-ad6f-57296b785273",
    "eventPayload": {
      "message": "Enter message here",
      "meta": null
    },
    "iso8601timestamp": "2024-03-14T01:24:38Z",
    "subscribeKey": "...",
    "timetoken": "17103794788490465",
    "senderId": "Jack-device"
  },
  "eventsAndActionsMetadata": {
    "eventListenerMetadata": {
      "eventListenerId": "d69b8f9c-5d24-47f0-81d0-98accd38fdba"
    },
    "actionMetadata": {
      "actionId": "96cb5d6c-c121-4a0d-a703-cd78be1099d0",
      "actionInstanceId": "f395ae94-0aaf-4ed7-9add-57ee9db30272",
      "actionInvocationId": "81f7ea47-dace-4812-b546-a26057c127ce",
      "webhookMetadata": {
        "retryMetadata": {
          "retryIntervalSeconds": 450,
          "attemptNum": 0,
          "maxNumRetries": 2
        }
      }
    }
  }
}
```

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

```js
// Add your code here. All actions will run unless you explicitly skip them.
// Quick tips!
// Auto-complete is on. Start typing to see ingredient options.
// Hover over any ingredient to see the variable type and an example.
// TypeScript v2.92
var json = JSON.parse(MakerWebhooks.jsonEvent.JsonPayload);

var message = json.event.eventPayload.message;

Sms.sendMeText.setMessage(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.

![](https://www.pubnub.com/cdn/3prze68gbwl1/32wxNb95y5H4Pc7I3OJuQp/57b25e2194e989536a5bac8df90c58f4/Screenshot_2024-03-13_at_11.00.19_PM.png)

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](https://www.pubnub.com/solutions/chat/) 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](https://www.pubnub.com/solutions/iot-device-control/) 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](https://ifttt.com/email) or [SMS](https://ifttt.com/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](https://ifttt.com/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.

-   [Make a Webhook call](https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-webhook-action) (i.e. call your server for each filtered event)
    
-   [Save to SQS](https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-sqs-action) (i.e. save each Event to [Amazon’s SQS queuing service](https://aws.amazon.com/sqs/))
    
-   [Send to Kinesis](https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-kinesis-action) (i.e. send to [Amazon’s Event Ingestion Service](https://aws.amazon.com/kinesis/))
    
-   [Send to S3](https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-s3-action) (i.e. store the data in an [Amazon S3 bucket](https://aws.amazon.com/s3/))
    
-   [Send to Kafka](https://www.pubnub.com/docs/serverless/events-and-actions/actions/create-kafka-action) (i.e. send the data to [Apache Kafka](https://kafka.apache.org/))
    

PubNub provides a wide set of [SDKs](https://www.pubnub.com/docs/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.

#### Contents

[Technical Overview](#h-0)[PubNub Event & Actions (E&A)](#h-1)[IFTTT and SMS Notifications](#h-2)[Prerequisites](#h-3)[Connecting PubNub with IFTTT](#h-4)[Developer Use-Cases](#h-5)[Chat Applications](#h-6)[IoT Device Monitoring](#h-7)[Getting started with PubNub](#h-8)

How can PubNub help you?
========================

This article was originally published on [PubNub.com](https://www.pubnub.com/blog/sms-notification-system-with-ifttt/)

Our platform helps developers build, deliver, and manage real-time interactivity for web apps, mobile apps, and IoT devices.

The foundation of our platform is the industry's largest and most scalable real-time edge messaging network. With over 15 points-of-presence worldwide supporting 800 million monthly active users, and 99.999% reliability, you'll never have to worry about outages, concurrency limits, or any latency issues caused by traffic spikes.

Experience PubNub
-----------------

Check out [Live Tour](https://www.pubnub.com/tour/introduction/) to understand the essential concepts behind every PubNub-powered app in less than 5 minutes

Get Setup
---------

Sign up for a [PubNub account](https://admin.pubnub.com/signup/) for immediate access to PubNub keys for free

Get Started
-----------

The [PubNub docs](https://www.pubnub.com/docs) will get you up and running, regardless of your use case or [SDK](https://www.pubnub.com/docs)