I have been slowly working on a needle command, to put tags onto user threads, which can then be used to come up with basic stats and analytics.
Learning some basic Typescript
, familiarizing with the needle bot code-base.
Learning about slash commands, the slash command builder…
Link to the command gist at the end of this post
I actually started this as a side-kick bot for needle. It’s own bot with its own commands. But after browsing around in the needle source code, it started to make sense (I know close to nothing about Typescript).
So I switched gears and dove into creating a new needle command.
I crammed all the tagging
logic into just one file, so that including this new command into your setup would not be too much of a hazzle/inconvenience. It’s one command with a handful of subcommands.
There is one env
variable that will be needed in your .env
file.
+ ES_DOMAIN=<url-to-elastic-search-domain>
The tagging data is persisted into an elasticsearch instance. For communication with the persistence layer, I went with axios
npm i axios --save
This section will go thru the process of getting a free elasticsearch in the cloud, but you can use your own if you have one spinning somewhere…
You can get a free-tier at searchly.com that provides everything that is needed.
Once on your searchly dashboard, navigate to Connection
> API Connection & Key
and locate your full domain url including the API Key:
This is the value that you would put into your env
variable ES_DOMAIN.
The searchly free-tier will allow you to create 2 indices before asking for an upgrade. We just need one index.
We will name the index threads
Do not create the index using their control panel. Instead we will PUT
the index along with some property definitions.
Using your fullaccess URL (the one from screengrab above), we will PUT
this data to
PUT <Your-Fullaccess-URL>/threads
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"created": { "type": "date" },
"updated": { "type": "date" },
"tags": { "type": "keyword" }
}
}
}
Explicitly setting created
and updated
fields to date
, and tags
to keyword
so queries and aggregations yield the expected outcome.
The data saved for a thread is
field | info |
---|---|
uid | The thread’s discord channel id. |
server | The thread’s discord guild id. |
created | When the tagging command was issued. |
update | When the latest tagging command was issued. |
status | No real purpose at the moment. |
tags | Array of tags for the thread. |
log | Array of tagging actions performed on this thread. |
"_source": {
"uid": "978152125286739968",
"server": "620112554211147807",
"created": "2022-05-23T04:36:45.983Z",
"updated": "2022-05-23T04:36:45.983Z",
"log": [
{
"who": "readonlychild",
"av": "https://cdn...976d37.webp",
"when": "2022-05-24T04:28:43.658Z",
"what": "add: unk-test"
}
],
"tags": [
"vue",
"cli",
"tailwind-css",
"css",
"unk-test"
],
"status": "blocker"
}
List the current thread tags
Command requires MANAGE_THREADS
permission.
Command only works on thread
channels
Clear tags for the current thread
Command requires MANAGE_THREADS
permission.
Command only works on thread
channels
Add a list of tags to the current thread
Replace tags for the current thread
Command requires MANAGE_THREADS
permission.
Command only works on thread
channels
Set a status for the current thread
Command requires MANAGE_THREADS
permission.
Command only works on thread
channels
Command does not require any permissions.
List top 25 tags
Here is the gist for the command.
Add logic to allow someone without permission MANAGE_THREADS
but does have a role like support-squad
to also use commands
/tags view | add | replace | clear
Searchly let’s you create other access endpoints, and one option is to make it read-only
, so it is a safe endpoint to use client-side.
I may create one or a couple of astro components to display some statistics about the tags .