Command scripts
Use scripts when command variables are not enough.
Scripts can:
- Send chat messages with
ctx.sendMessage. - Reply to the source chat message by passing
ctx.input.provider_message_idas the reply message ID. - Call public HTTP APIs with
fetch. - Store values with
ctx.kv.
Quick setup
Section titled “Quick setup”- Open the Synchra Dashboard.
- Go to Commands.
- Create or edit a command.
- Add command triggers, phrase triggers, or activity triggers.
- Set the action to Custom script.
- Write the script.
- Test and save.
When It Runs
Section titled “When It Runs”The script runs only after one of the command triggers matches.
| Trigger type | What happens |
|---|---|
| Command trigger | A chat message starts with a matching !command. |
| Phrase trigger | A normal chat message matches one of the command’s phrase triggers. |
| Activity trigger | A matching activity is created for the command. |
Trigger data
Section titled “Trigger data”| Value | Meaning |
|---|---|
ctx.trigger | chat_message or activity. |
ctx.command | Match data with exactly trigger and args. |
ctx.command.trigger | The matched command trigger, pattern, or activity. |
ctx.command.args | Command arguments. Empty for phrase triggers. |
ctx.input | Channel, provider, viewer, message text, message parts, timestamps, IDs, and access level. |
ctx.activity | Activity fields for activity runs. null for chat runs. |
ctx.mode | test or live. |
KV storage
Section titled “KV storage”| Method | Meaning |
|---|---|
ctx.kv.get | Read a value. Missing and expired values return null. |
ctx.kv.set | Store or replace a JSON-compatible value. |
ctx.kv.delete | Remove a value. |
ctx.kv.inc | Increment an integer value and return the new number. |
KV values must be JSON-compatible: strings, numbers, booleans, null, arrays,
and plain objects. Keys may contain letters, numbers, :, _, ., /, and
-. TTL values are in seconds.
Code examples
Section titled “Code examples”Chat game command
Section titled “Chat game command”Setup: command trigger guess.
Chat guesses a number from 1 to 10. The answer stays the same until someone wins.
Activity prize roll
Section titled “Activity prize roll”Setup: activity trigger for subs, resubs, gift subs, donations, or Super Chats.
Each matching activity gets a 10% chance to win.
See activity fields for the values on ctx.activity.
Redeem streak counter
Section titled “Redeem streak counter”Setup: activity trigger for the Daily check-in redeem.
Track a per-user streak. If the user waits too long, their count starts over.
Fetch from an API
Section titled “Fetch from an API”Setup: command trigger challenge.
Fetch a challenge from your own site or API.