Skip to content

dnywh/ephemerabot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A robot made up of ticket stubs, receipts, and other analogue bits and bobs

Ephemerabot

Ephemerabot is a Twitter bot cousin of the Ephemera project. Ephemerabot checks for and tweets out new scraps of ephemera daily. Any new ephemera also causes the Ephemera website to rebuild using Netlify build hooks.

This repo might be useful to you if:

  • You're interested in making a Twitter bot
  • Your ideal Twitter bot reads and writes images
  • You'd like to transform images via Node
  • You're interested in using the Airtable API
  • You're interested in automatically deploying Netlify sites

Getting started

Here's how to get this project working locally.

Prerequisites

  • Node.js (v18 and above) and npm
  • An Airtable base and API key (instructions here)
  • A Twitter developer account and API key

And if you'd like to make Ephemerabot automatically deploy you'll need to either:

  • Prepare a Netlify site with a build hook URL
  • Comment-out the fetch(rebuild_url, { method: 'POST' }) line in server.js

Installation

  1. Clone this repo
git clone https://github.com/dnywh/ephemerabot.git
  1. Install the NPM packages
cd ephemerabot
npm install
  1. Create a file called .env and enter values for the variables shown in .env.example
TWITTER_API_KEY=
TWITTER_API_SECRET_KEY=

TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_SECRET=

AIRTABLE_API_KEY=
AIRTABLE_BASE_ID=

REBUILD_URL=

Usage

Here's how to get Ephemerabot going, assuming you have followed the above instructions and have:

  1. API keys for both Twitter and Airtable
  2. An Airtable base set up similarly to mine (instructions here)

Running locally

npm start

Consider using one of the two core functions currently commented-out for debugging. Otherwise Ephemerabot will just wait for its scheduled time to post.

Ephemerabot loves to chat. Keep an eye on the terminal to see how things are progressing.

Tweeting latest ephemera

Ephemerabot looks at the tweeted value of each record to see if it has been tweeted yet. Once tweeted, records have this value to true. The aforementioned instructions include an example base with a tweeted column. Try setting one or two records' tweeted value to false to have them recognised and tweeted by the tweetLatestEphemera() function.

To use the tweetLatestEphemera() function in debug mode:

  1. Make sure your connected Airtable base has at least one record with its tweeted value set to false
  2. Uncomment tweetLatestEphemera() in the debugging section (at the bottom) of server.js
  3. If you just want to debug locally (and not kick off a real tweet): Comment-out kickOffTweet(record, false) within the main tweetLatestEphemera() function
  4. Run npm start
  5. Keep an eye on your console for the results

Running externally

Running Node on your computer is the only way Ephemerabot lives, unless you deploy this app to a server. You'll need to sign up to a service such as Heroku to do so. Daniel Shiffman has a few videos on this that are beginner-friendly.

Once you have set up a Heroku account and installed the Heroku CLI:

  1. Enter your API keys as Config Vars inside your Heroku dashboard's Settings page
  2. Push your project to Heroku:
git push heroku main

Image hosting

To use your own images you'll need to use a service like Cloudinary and change the imageDirectory value in server.js.