This small node.js application intends to show a simple way of performing an action when an AT&T M2X Data Source Trigger is fired, in this case sending an email through the SendGrid API. In order to make setup easier we're assuming you will use Heroku to deploy the application, although you can using any compatible application hosting service.
- Signup/Login to Heroku and create a new application
- Add the SendGrid Add-on
- Set the following env variables on heroku using your SendGrid credentials: SENDGRID_USERNAME, SENDGRID_PASSWORD
- Edit the main.js file and set constants for the notification emails. Push those changes to Heroku.
- In your application root directory run
heroku ps:scale web=1to start one dyno of your application. - You can check the status by going into the
/statuspath, of your published application URL.
- Signup for an AT&T M2X Account.
- Create your first Device
- Add a Stream to your Device
- Add a Trigger to your Device Stream and point the callback URL to the domain where your application will be hosted (Heroku will provide you with this URL). By default, the URL path will be
/email-trigger, so an example URL would be: http://your-domain.com/email-trigger - Start pushing values to your Device Stream.
Please consult the AT&T M2X glossary if you have questions about any M2X specific terms.
Once everything is setup and values are being pushed to your Stream, every time a value meets the Trigger's condition the API will send a request to your application at the URL provided. The application will then process the request and send an email to the address specified in the code (environment variables could be used for storing these values instead of being hardcoded in the source).
This application is delivered under the MIT license. See LICENSE for the specific terms.