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.
The following environment variables should be configured:
- AIR_QUALITY_API: The HTTPS URL to your AirVisual Node API obtained from your AirVisual devices dashboard in format https://www.airvisual.com/api/v2/node/{uniqueDeviceApiLink}
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
Make sure you have Node.js as well as npm
installed.
- Clone this repo
- Install the dependencies
# Install the dependencies of the Twilio Function
npm install
- Copy the
.env.example
file:
cp .env.example .env
- Edit
.env
:
AIR_QUALITY_API=https://www.airvisual.com/api/v2/node/XXXXXXXXXXXX
# Start Twilio Functions
npm run start
Your function will run on http://localhost:3000
.
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.