Your First Automation
Let’s build a simple automation: when someone types !dice in Twitch chat, the bot rolls a random number and replies.
Prerequisites
Section titled “Prerequisites”- A Rawtoh account at app.rawtoh.io
- A Twitch module connected and online
Step 1: Create the action
Section titled “Step 1: Create the action”- Open the Script panel
- Click New Action
- Set the path to
twitch/dice-roll - Paste this code:
const user = event.payload.user;const roll = Math.floor(Math.random() * 6) + 1;
await module.request("twitch", "sendMessage", { text: `@${user} rolled a ${roll}! 🎲`});
log("Dice roll:", user, "got", roll);- Save
Step 2: Create the trigger
Section titled “Step 2: Create the trigger”- Click New Trigger on your action
- Set:
- Module group:
twitch - Event name:
ChatMessage - Cooldown:
2000(2 seconds, to prevent spam)
- Module group:
- Write the condition:
event.payload.message.toLowerCase().startsWith("!dice")- Save
Step 3: Test it
Section titled “Step 3: Test it”Go to your Twitch chat and type !dice. You should see:
- An event appear in the Events panel
- A process showing the trigger matched and the action ran
- The bot reply in chat with a random number
What’s happening behind the scenes
Section titled “What’s happening behind the scenes”- The Twitch module detects the
!dicemessage and emits aChatMessageevent - Rawtoh receives the event and checks all triggers for
ChatMessageon thetwitchgroup - Your trigger condition evaluates —
"!dice".startsWith("!dice")returnstrue - The action runs: generates a random number and calls
module.requestto send a reply - The Twitch module receives the command and posts the message in chat
All of this happens in a few milliseconds.
Next steps
Section titled “Next steps”- Add more commands by creating new actions and triggers
- Use storage to remember data between executions
- Explore Writing Actions for more advanced patterns