Lurk Message API

Overview

This is an API that was primarily designed for use with Nightbot for the Twitch channels that I moderate for.

I’ve wanted to make Nightbot behave in this way since I first started making dynamic lurk responses in it, but it’s never been possible without any additional tooling, so I decided to just make an external tool do it after a while of not being able to find one that worked the way I wanted it to.

The way this system works, is each channel has a number of associated “message groups” which each have a number of lurk and unlurk messages (at least one of each). When a user requests a lurk message the API chooses one of the message groups randomly, then it selects a lurk message at random, and saves which message group we used to give the user a message from. Once the user requests an unlurk message, we pull the group ID that was stored when they retrieved a lurk message, and pull a random unlurk message from that message group, deleting the stored group ID, if the request is for a user that doesn’t have a stored group ID associated with them, then the API will return a static “default unlurk message” that every channel has in the system, this default message is to prevent weird technical-errors from being sent as the response to the request.


Development

Primary Technologies

Authentication

The endpoints that require authentication use Basic authentication provided by the @hapi/basic module, with the accounts specified in the config.toml.

Endpoints

This APIs primary function comes in the form of two endpoints:

  • GET /{channel}/lurk
  • GET /{channel}/unlurk

both of these endpoints return a string formatted with the appropriate variables.

However there is a multitude of other endpoints for managing and maintaing information for each channel’s lurk message groups. Each of these endpoints can be found below.

Get /{path*}

Static file server, this is used for the website that allows users to manage the message groups.

POST /login

The endpoint that the website communicates with allowing users to access the channels that they have permission to view.

POST /manage

This endpoint allows creating channels in the database.

POST,PUT /manage/{channel}/message

Creates a new message group for the specified channel.

DELETE /manage/{channel}/message/{id}

Removes the specified message group from the channel.

GET /manage/{channel}

Retrieve all of the database data for the given channel.

DELETE /manage/{channel}/lurkers

Purge the database of all users that have a saved message group ID.

PATCH /manage/{channel}

Allows updating the channel’s non-message-group information, like the default unlurk message.

PATCH /manage/{channel}/message/{id}

Updates a specific message group in the channel, this can be used to add, delete, or edit any lurk/unlurk messages in that group. Both lurk and unlurk messages must be provided in the request.


Oliver Akins © 2022. All rights reserved.