Provides an endpoint for Nightbot or other twitch bots to consume via fetch.
- PHP 8.2
- Composer
- Hosting service
- Domain name
We are using the .env file outside of the web root as a security paradigm, so your secrets are contained within the .env file and are not web accessible.
To get started, copy .env.example
to .env
, and change the values.
OPENAI_API_KEY
Should be your OpenAI API Key provided by OpenAI here:
OPENAI_PROMPT_CONTEXT_URL
Should be the RAW URL to your github txt file containing your context, this URL usually starts with https://raw.githubusercontent.com
, and can be found by clicking the "Raw" button (top right) on your file.
You will need to host this on a hosting service so that it's accessible from a domain name. You will also need to point a domain name at your hosting service.
git clone the repository to your hosting service:
git clone https://github.com/MadMikeyB/twitch-openai-api.git .
Run composer install
composer install
Run the steps in Secrets above to change .env.example to .env
Point your hosting services "public directory" to "public/".
To send input from Twitch chats to your endpoint using Nightbot's URL fetch feature, follow these steps:
Go to Nightbot and log in with your Twitch account.
- Go to the
Commands
section on the Nightbot dashboard. - Click on
+ Add Command
.
- Command: Set the command trigger word. For example, if you want to trigger the endpoint with
!nightbot
, type!nightbot
here. - Message: Use the URL fetch feature to send a request to your endpoint. The format will be:
$(urlfetch https://example.com/index.php?user=$(user)&prompt=$(querystring))
Here’s an example configuration:
- Command:
!nightbot
- Message:
$(urlfetch https://example.com/index.php?user=$(user)&prompt=$(querystring))
Click the Submit
button to save your new command.
Now, when someone types !nightbot <message>
in your Twitch chat, Nightbot will send a request to https://example.com/index.php
with the Twitch username and the message.
For example, if a user named TwitchUser123
types:
!nightbot Hello, this is a test message!
Nightbot will send a request to:
https://example.com/index.php?user=TwitchUser123&prompt=Hello,%20this%20is%20a%20test%20message!
This setup allows you to dynamically send Twitch chat messages to your endpoint using Nightbot.