AWS | Twitter Joke Bot

Twitter bot that will periodically tweet out a joke obtained from a joke API.

Clone This Example

Step #1 - npm install serverless -g
Step #2 - serverless install -u https://github.com/serverless/examples/tree/master/aws-node-twitter-joke-bot -n  aws-node-twitter-joke-bot

Joke Twitter Bot

Description

This is a Twitter bot that will periodically tweet out a joke obtained from a joke API https://icanhazdadjoke.com/

Installation

Run npm i to install dependencies

Setup

An environment file is required to contain the secret keys for the Twitter API and the joke API's URL. The naming convention for this file is [STAGE].env.json, for example dev.env.json.

This is the env file that should be placed in the project root.

{
    "JOKES_API_URL":"https://icanhazdadjoke.com/",
    "TWITTER_CONSUMER_KEY": "YOUR KEY GOES HERE",
    "TWITTER_CONSUMER_SECRET": "YOUR KEY GOES HERE",
    "TWITTER_ACCESS_TOKEN_KEY": "YOUR KEY GOES HERE",
    "TWITTER_ACCESS_TOKEN_SECRET": "YOUR KEY GOES HERE"
}

Testing

The bot can be invoked manually during development with the following command

sls invoke local -f bot

Deployment

  • Both the STAGE and REGION options can be used with this bot. If left out the bot will default to dev stage and eu-west-1 region.

Deploy command

sls deploy --stage dev --region eu-west-1

Notes

The API request in helpers/jokes.js sets a custom User-Agent header to identify users to the joke API owners. Please customise this to your library name.

view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g