# Otag example app A small app for Otag. Added to a server, it says hello in the channel you pick, with a **Say hello** button. `/hello` answers you alone with a card; its **Wave** button changes that card, and **Say something** opens a form whose words the app posts in the channel, or tells only you. It shows what most apps use: a hello when it is added, a command, a card with buttons, a form, a reply only one person sees, a message in the channel, the person's language, and the check that a request really comes from Otag. The guide to building apps: https://api.otag.chat/developers ## What you need - Node.js 22.18 or newer: it runs the TypeScript as it is, with nothing to build. - An Otag account, and a server where you have Manage Server to try the app in. ## 1. Make the app In Otag, open Settings → Developer → New app and name it. Otag shows the app's **token** once: copy it. On the app's page, copy its **app ID**, turn on **View channels** and **Send messages** under "It asks to", and save. ## 2. Run it Set these in the environment the app runs in: | Variable | What it is | |---|---| | `OTAG_BASE` | The Otag server: `https://api.otag.chat` | | `OTAG_APP_ID` | The app ID from step 1 | | `OTAG_TOKEN` | The token from step 1 | Then: ```sh npm install npm start ``` `npm install` only brings TypeScript, for `npm run check`; the app itself needs no packages. It gives Otag its `/hello` command and connects to Otag's gateway as the app, so it needs no address of its own. It prints `connected to Otag as …` when it is ready. ## 3. Add it to your server In Otag, open Server settings → Integrations, paste the app ID under "Add by link or ID", choose what it may do, who may use it and where it says hello, and add it. Its hello appears in that channel. ## 4. Try it Press **Say hello** on its hello, or in one of the server's text channels type `/hello`, or press + and choose it there. ## Answering at an address instead The gateway suits your own computer. For an app that runs on a server, Otag can post each interaction to the app's address instead: 1. Also set `PORT` (the port to listen on) and `OTAG_SIGNING_SECRET` (the signing secret on the app's page in Settings → Developer). The app then answers Otag's signed POSTs at `/interactions` and refuses any it can't verify. 2. Make that reachable from the internet over https, at an address of yours or through a tunnel to your computer. 3. Set the app's **Interactions address** in Settings → Developer to that address with `/interactions` at the end, and save. Otag pings it first, and the app must answer. While an app has an interactions address, Otag sends it everything there and nothing over the gateway. ## The files - `src/app.ts`: what the app does, its command and its answers, in English and Turkish. - `src/otag.ts`: Otag's shapes, the signature check and calls to Otag's API. - `src/index.ts`: starts it, over the gateway or at an address. `npm run check` type-checks them.