Make sure that postgres is running on localhost:5432
with postgres:password
as the credentials. (If you're running xtp locally, this should already be the
case!)
- Copy
env.example
to.env
. - Create a Discord test server for local dev.
- Create a Discord app and bot.
- Click "New Application" on the Discord dev portal.
- Call it
xtp (local)
- Navigate to the "Installation" drawer tab.
- Make sure only "Guild install" is checked.
- Under "default install settings":
- Scopes: Add "application.commands" and "bot".
- Permissions:
- Add Reactions
- Attach files
- Ban members
- Embed links
- Manage Messages
- Read message History
- Read messages / view channels
- Send Messages
- Use Slash commands
- To add the bot to your server, click the link under "Install Link".
- Navigate to the "Bot" drawer tab.
- Click the "Reset Token" button. Save the token as
DISCORD_BOT_TOKEN
. - Uncheck "public bot".
- Check "PRESENCE INTENT".
- Check "SERVER MEMBERS INTENT".
- Check "MESSAGE CONTENT INTENT".
- Click the "Reset Token" button. Save the token as
- Link an XTP app.
- The app should be on staging or local.
- For local use
http://localhost:8080
. - For staging use
https://xtp-staging.dylibso.com
- For local use
- Now login using the xtp CLI:
xtp auth login -e REPLACEME_WITH_XTP_ENDPOINT
.- Grab the token using
xtp auth token show
and edit.env
'sXTP_TOKEN
value to reflect that token. - Grab an app id using
xtp app list
. It'll look likeapp_2gv3krz3ry8658t5cbebnbnppy
. SetXTP_APP_ID
in.env
to that value.
- Grab the token using
- Just one more thing. :colombo:
- Go to your app on the XTP environment you chose. That's
http://localhost:8081
if you're running locally orhttps://xtp-staging.dylibso.com
otherwise. - Create an extension point named
chat
. - That extension point should use the schema from
./plugin.yaml
.
- Go to your app on the XTP environment you chose. That's
- The app should be on staging or local.
You're just about ready. Now you can run:
$ psql postgres://postgres:password@localhost/xtp -c 'create database discordbot;'
$ npm ci
$ npm run migrate
$ npm run dev
When we switch from xtp-staging to xtp for the deployed service:
- We need to change the
XTP_TOKEN
GitHub secret to an admin of the XTP env's app. - We need to create two extension points on that app: one for testing and one for prod.
- The testing extension ID needs to go in
.github/workflows/ci.yaml
replacingEXTENSION_ID
. - The prod extension ID needs to go in
.github/workflows/cd.yaml
replacingEXTENSION_ID
.
- Make a GitHub app.
- the "Application name" should be something like "discordbot (dev)".
- "Homepage URL" doesn't really matter, but maybe point it to XTP?
- Authorization callback url MUST
http://localhost:8124/login/github/callback
for local dev. - Word to the wise: DO NOT PASS GO. DO NOT TAKE 200 DOLLARS.
- Take the client id and secret and put them in your 1Password private vault.
- Now go edit your
.env
.OAUTH_GITHUB_CLIENT_ID
andOAUTH_GITHUB_SECRET
should reflect the respective values you just saved in your vault. - You did save them, right?
- Okay. I'll believe you. But I've got my eyes on you!