Skip to content

Twilio Function to retrieve IQ Air Visual Pro device data and return Messaging/SMS TwiML

Notifications You must be signed in to change notification settings

randyjohnston/function-twilio-iq-air-quality

Repository files navigation

iq-air-twilio-function

This project uses a Twilio function to query an AirVisual Pro device-specific API endpoint and respond with the CO2 concentration or PM2.5 for the configured device as Messsaging TwiML. You must have an AirVisual Pro device linked to an iqair.com account as well as a Twilio account to make use of this respository.

Environment variables

The following environment variables should be configured:

Requirements

To deploy this plugin, you will need:

  • npm version 5.0.0 or later installed (type npm -v in your terminal to check)

  • Node.js version 12 or later installed (type node -v in your terminal to check)

  • Twilio CLI along with the Serverless Plugin. Run the following commands to install them:

    # Install the Twilio CLI
    npm install twilio-cli -g
    # Install the Serverless and Flex as Plugins
    twilio plugins:install @twilio-labs/plugin-serverless

Setup

Make sure you have Node.js as well as npm installed.

  1. Clone this repo
  2. Install the dependencies
  # Install the dependencies of the Twilio Function
  npm install
  1. Copy the .env.example file:
cp .env.example .env
  1. Edit .env:
AIR_QUALITY_API=https://www.airvisual.com/api/v2/node/XXXXXXXXXXXX

Development

# Start Twilio Functions
npm run start 

Your function will run on http://localhost:3000.

Deploy

When you are ready to deploy your plugin, first deploy your Twilio Functions:

twilio serverless:deploy

You will see your service and function deployed in the Twilio Functions console. Note that the function is protected so it is not publicly accessible (see Understanding Visibility of Functions and Assets). Your Function will be available to configure as a webhook handler for your Twilio number.

About

Twilio Function to retrieve IQ Air Visual Pro device data and return Messaging/SMS TwiML

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published