Texting service to receive current air quality conditions and maps, powered by AirNow, Twilio, and AWS

Overview

Air Quality Bot - Text (415) 212-4229

CI/CD Codecov Python Versions GitHub License Tweet

The Air Quality Bot is generally available by texting a zip code (and optionally the word "map") to (415) 212-4229. The bot will respond with the latest air quality report for your region.

The instructions below illustrate how to similarly setup the bot in your own AWS and Twilio environments.

Getting Started

AWS Initial Setup

Create a new Role from a Policy with the following permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "cloudwatch:PutMetricData",
                "dynamodb:CreateTable",
                "dynamodb:GetItem",
                "dynamodb:PutItem",
                "dynamodb:UpdateItem",
                "dynamodb:DescribeTable",
                "dynamodb:GetShardIterator",
                "dynamodb:GetRecords",
                "dynamodb:ListStreams",
                "dynamodb:Query",
                "dynamodb:Scan"
            ],
            "Resource": "*"
        }
    ]
}

Install and configure the AWS CLI for the same account for which the Role was created.

AWS Lambdas

Initialize the deployment environment by running make install locally, then edit the .env file's AWS_ROLE with the ID of the Role created above and the AIRNOW_API_KEYS list with one or more AirNow API keys.

Note that, on initial deploy, your Lambdas will be pointing to the an endpoint that does not exist until you complete the AWS API Gateway Routes section below and update the AIR_QUALITY_API_URL variable to point to the deployed endpoint.

Deploy the Lambdas to your AWS environment using the deploy script:

./deploy.sh

Optionally, TTL for ZipCode fields in the DynamoDB table can be enabled by going to the AWS console and enabling TTL on the TTL field.

AWS API Gateway Routes

Create an API Gateway. In the API, do the following:

  • Create a new "Resource" with a path of /inbound
    • Create a new "POST" method with the "Integration type" of "Lambda Function" and point it to the Lambda AirQuality_inbound_POST
      • Edit the "POST" method's "Integration Request"
        • Under "Mapping Templates", add a "Content-Type" of application/x-www-form-urlencoded using the "General template" of "Method Request Passthrough"
      • Edit the "POST" method's "Method Response"
      • Edit the 200 response so it has a "Content type" of application/xml

Last, under the "Integration Response" for /inbound, edit the 200 response. Under "Mapping Templates" of "Content-Type" of application/xml with the following template:

#set($inputRoot = $input.path('$'))
$inputRoot.body

Additionally, create the following "Resource" paths:

  • /aqi

Under each of the above, do the following:

  • Create a new "GET" method with the "Integration type" of "Lambda Function" and point it to the Lambda AirQuality_<ROUTE_NAME>_GET, where <ROUTE_NAME> corresponds to the name of the Lambda we created to execute on this method
    • Edit the "GET" method's "Method Request"
      • Change the "Request Validator" to "Validate query string parameters and header"
      • Add a required "URL Query String Parameter" of zipCode
      • Edit the "GET" method's "Integration Request" - Under "Mapping Templates", add a "Content-Type" of application/json using the "General template" of "Method Request Passthrough"

Deploy the new API Gateway. Note the newly generated Invoke URL and update the AIR_QUALITY_API_URL variable in .env, then redeploy your Lambdas by running ./deploy.sh again.

Setup Twilio

In Twilio, create a phone number and set it up. Under "Messaging", select "Webhook" for when "A Message Comes In", select "POST", and enter the deployed API Gateway URL for /inbound.

That's it! Your bot is now setup and ready to respond to texts.

Local Development

To test the bot locally, simple Flask server is included in devserver.py. Ensure proper dev values are in .env.dev, then execute:

make run-devserver

This will start a server with the appropriate routes and in-memory datastores, and it will also start a ngrok tunnel using pyngrok so the bot can be fully tested end-to-end.

CI Build

If you would like the project to build for you in a CI system, you may need to add the following environment variables to the CI's console. Their actual values do not matter (use dummy values, not real), but certain versions of the boto dependency need them to be present when initializing its configuration.

  • AWS_ACCESS_KEY_ID
  • AWS_DEFAULT_REGION
  • AWS_SECRET_ACCESS_KEY

Deploy Updates

After the initial installation in to your AWS environment, updates to the Lambdas can easily be redeployed at any time by rerunning the deploy script:

./deploy.sh
Owner
Alex Laird
Leader โ€ข Software Creator โ€ข Visionary โ€ข Learner โ€ข [he/him] Engineer @ Twilio
Alex Laird
This software's intent is to automate all activities related to manage Axie Infinity Scholars. It is specially aimed to mangers with large scholar roasters.

Axie Scholars Utilities This software's intent is to automate all activities related to manage Scholars. It is specially aimed to mangers with large s

Ferran Marin 153 Nov 16, 2022
This bot is created by AJTimePyro and It accepts direct downloading url & then return file as telegram file.

URL Uploader Bot This is the source code of URL Uploader Bot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Abhijeet 23 Nov 13, 2022
Send SMS text messages via email with as many accounts as you want :)

SMS-Spammer Send SMS text messages via email with as many accounts as you want :) Example Set Up Guide! To start log into the gmail account you would

Riceblades11 10 Oct 25, 2022
๐Ÿ›’ Bot de lista de compras compartilhada para o Telegram

Lista de Compras Lista de compras de Cuducos e Flรกvia. Comandos do bot Comando Descriรงรฃo /add item Adiciona item ร  lista de compras /remove item

Eduardo Cuducos 4 Jan 15, 2022
SelfBot, a lots of features: Mass DM , Nuke, Raid... and more!

SelfBot, a lots of features: Mass DM , Nuke, Raid... and more!

eryycr 2 Nov 10, 2021
A simple, infinitely scalable, SQS based queue.

SimpleQ A simple, infinitely scalable, SQS based queue. Meta Author: Randall Degges Email: [emai

Randall Degges 162 Dec 21, 2022
A Telegram Bot Plays With Words!!!

TheWordzBot โž  I Can Turn Text Into Audio โž  I Can Get Results From Dictionary โž  I Can Make Google Search For You โž  I Can Suggest Strong Passwords For Y

RAVEEN KUMAR 8 Feb 28, 2022
Wordle-bot: A Discord bot to track you and your friends' Wordle scores.

wordle-bot A Discord bot to track you and your friends' Wordle scores, so you can see who's the best! To submit a score to wordle-bot, just paste the

Spencer Murray 8 Feb 16, 2022
Most Simple & Powefull web3 Trade Bot (WINDOWS LINUX) Suport BSC ETH

Most Simple & Powefull Trade Bot (WINDOWS LINUX) What Are Some Pros And Cons Of Owning A Sniper Bot? While having a sniper bot is typically an advanta

GUI BOT 6 Jan 30, 2022
A simple script that loads and hot-reloads cogs when you save any changes

DiscordBot-HotReload A simple script that loads and hot-reloads cogs when you save any changes Usage @bot.event async def on_ready(): from HotRelo

2 Jan 14, 2022
An Open Source ALL-In-One Telegram RoBot, that can do lot of things.

An Open Source ALL-In-One Telegram RoBot, that can do lot of things.

JOBIN 0 Dec 01, 2021
AWS Blog post code for running feature-extraction on images using AWS Batch and Cloud Development Kit (CDK).

Batch processing with AWS Batch and CDK Welcome This repository demostrates provisioning the necessary infrastructure for running a job on AWS Batch u

AWS Samples 7 Oct 18, 2022
The records of 42 million users from a third-party version of the popular Telegram messaging app have just been Iranian accounts leaked

TelegramDatabase About The records of 42 million users from a third-party version of the popular Telegram messaging app have just been Iranian account

Hamed Mohammadvand 10 Jan 14, 2022
This is a Telegram Bot that tracks packages from the Brazilian Mail Service.

RastreioBot About Setup Run Contribute Contact About This is a Telegram Bot that tracks packages from the Brazilian Mail Service. It runs on Python 3

Gabriel R F 320 Dec 22, 2022
fair-test is a library to build and deploy FAIR metrics tests APIs supporting the specifications used by the FAIRMetrics working group.

โ˜‘๏ธ FAIR test fair-test is a library to build and deploy FAIR metrics tests APIs supporting the specifications used by the FAIRMetrics working group. I

Maastricht University IDS 6 Oct 30, 2022
A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create cust

Aran 1 Oct 13, 2021
Python interface to the LinkedIn API

Python LinkedIn Python interface to the LinkedIn API This library provides a pure Python interface to the LinkedIn Profile, Group, Company, Jobs, Sear

ozgur 844 Dec 27, 2022
Date Time Userbot With Python

DATE_TIME_USERBOT An Telegram Bot By @Pythone_3 Config Vars API_ID : Telegram API_ID, get it from my.telegram.org/apps API_HASH : Telegram API_ID, get

Sinzz-sinan-m 2 Oct 20, 2021
Slack bot to automatically delete yubisneeze / accidental yubikey presses

YubiSnooze Slack bot to automatically delete yubisneeze / accidental yubikey presses. It will search using the regex "[cbdefghijklnrtuv]{44}" and if t

Andrew MacPherson 3 Feb 09, 2022