Add or Remove ChatIDs to a TICK Script Automatically

I’m trying to allow a user to “opt-in” or “opt-out” of receiving alerts via Telegram.
So far I know that I can have multiple ChatIDs per alerts as follows:

var triggerTemp = temp
.crit(lambda: “temp” > upperTempCrit OR “temp” < lowerTempCrit)
.message(deviceName + ’
Temperature changed to{{if eq .Level “CRITICAL”}} CRITICAL {{else if eq .Level “OK”}} OK {{end}}
Reading: {{ index .Fields “temp” }}°C
Time: {{ .Time.Local.Format “Mon, Jan 2 2006 at 15:04:05 MST” }}’)

Is there a way to add/remove/edit these TICK scripts with data from a database or text file or something similar so that when a user opts in or out they can be added or removed?

have you tried the sideload node ?
This allows the tick script to read in data from a configuration file.
I have used the functionality to read in maintenance windows, and server specific thresholds, but not to add a variable number of chat ids.

Alternatively you can define these scripts via the kapacitor API, so could you periodically read your database of subscribers and then using the API delete and re-define the tick script with the desired subscribers ?

I found the sideload docs, but I’m not 100% sure how I could use it to add or change the TICK script, could you perhaps provide an example of how you got yours working?

I have used sideload node to override thresholds. So in my check_cpu script I have warning_threshold=70 and crit_threshold=90
for each server that I want to change these values I create a .yml file with the contents:
The sideload looks like:
stream from…
| alert
.crit(lambda: (“cpu” >“crit_threshold”))
.warn(lambda:(“cpu” >“warning_threshold”))

Could this work ?

My second suggestion was to use an external program to create a task based on who was interested.
Assuming you had the names in a DB you could create a task per receiver using the Define or update task API

then the pseudo code would look like:
//delete all existing tasks
For each name in get_names()
POST /kapacitor/v1/tasks
{ “id” : “send_to_$name”,
“template-id” : “mytemplate”
“vars” :{
“receiver” : {
“value” : $name
“type” : string