Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

shotstack-samples/build-me-a-video-twitter-bot

Repository files navigation

Build Me A Video Twitter Bot

Create a Twitter bot that creates videos from tweets using the Shotstack API.

This project uses AWS Lambda via the Serverless framework, Shotstack, node-twitter-api-v2 to query any Twitter mentions and create a personalised video from tweet and user data.

This project creates three Lambda functions:

  1. Query function that checks for new mentions every minute and creates a personalised video for each mention.
  2. Webhook function that accepts a Shotstack callback and executes the lambda which will reply to the Tweet.
  3. Reply function which uploads the Shotstack video to Twitter when the render completes and tweets the result as a reply to the original tweet.

Install

Register for a Shotstack developer account and a Twitter developer account.

npm install
cp .env.dist .env

Twitter authentication

For the Twitter API we use OAuth1.1. You can generate your API (consumer) keys and associated access token and secret on your dashboard. You will likely have to apply for elevated account access.

Once you have your Twitter credentials add them to your .env file, in addition to your Twitter user ID.

Shotstack authentication

For Shotstack you can access your API keys via your dashboard. Add your sandbox or production key to your .env file and use the appropriate environment. v1 for production and stage for the sandbox.

AWS

To deploy the application you will need an AWS account. The easiest way to deploy from your local machine is if the AWS CLI is already installed. To install and configure the AWS CLI follow the Getting started with the AWS CLI guide.

Other ways to authenticate your AWS account are explained in the Serverless AWS Credentials guide.

Deployment

First create a deployment bucket in AWS S3 and then add the bucket name to the DEPLOYMENT_BUCKET environment variable in your .env file. Alternatively you can allow the Serverless Framework to create a deployment bucket for you by deleting the following lines from serverless.yml:

  deploymentBucket:
    name: ${env:DEPLOYMENT_BUCKET}
    blockPublicAccess: true

Next deploy the application:

npm run deploy

Now copy your webhook API endpoint to your .env file and deploy your serverless project again:

npm run deploy

Note that you can override the stage and region parameters using options:

npm run deploy -- --stage production --region us-east-1

Built with

  • Shotstack - Shotstack provides a cloud based video editing API used to power applications that create, automate and personalise millions of data driven videos.
  • node-twitter-api-v2 - Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.

About

Create a Twitter bot that creates videos from tweets using the Shotstack API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published