Connect Railway to Botmotive
This page helps you connect a Railway service to Botmotive. Railway has no log drain, so Botmotive reads the service's HTTP logs every minute through its API.
These logs include requests your app answered with 403 or 429. Pulling only reads logs. To enforce fixes, add a guard to your app as well.
The quickest way is the form on your site's Railway install page: open your site, choose Railway, and fill in the Railway token, service ID, environment ID and domain described below. The page shows the connection status once it's saved. This guide also shows how to connect with two API calls, using curl and jq.
What you need first
- A Botmotive account and a site you own. See Getting started.
- Your site ID, such as
my-shop. It is shown in Settings next to Site ID. - For the API steps:
curlandjqon your computer. - For a guard: your ingest token, which starts with
bm_.
A new site starts with no token. The Railway connection doesn't use a token, but the guards do. Its install page makes one for you: open your site, choose Railway (or click Connection steps in Settings), and click Make a token. The token is shown only once, and Botmotive keeps only a hash of it. You can also make one in Settings:
- Open your site in the dashboard and click Settings.
- Under Tokens, click New token. Name it after what will use it, such as
Railway guard, and click Make token. - Click Copy and store the token somewhere safe.
Other tokens keep working. If an old token may have leaked, click Revoke next to it.
Install
Make a Railway token
- In Railway, open your project. Go to Project settings, then Tokens.
- Make a project token for the environment that serves your site, such as
production. - Copy the token.
The token can read that environment's variables. Botmotive stores it encrypted and never shows it again. Botmotive also accepts an account or workspace token, but a project token gives it the least access.
Find the service and environment IDs
Open your project in Railway and press Cmd + K (Ctrl + K on Windows and Linux). From that menu you can copy the service ID and the environment ID, as Railway's API guide describes. Pick the service that serves your site and the environment you made the token for. Each ID is 36 characters, like 0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b.
Get a session token
Sign in to the Botmotive API. This prints a session token that starts with bms_. It lasts 30 days.
read -r -p 'Botmotive email: ' BM_EMAIL
read -r -s -p 'Botmotive password: ' BM_PASSWORD; echo
BM_SESSION=$(curl -sS https://api.botmotive.io/v1/auth/login \
-H 'content-type: application/json' \
-d "$(jq -n --arg e "$BM_EMAIL" --arg p "$BM_PASSWORD" '{email: $e, password: $p}')" | jq -r .token)
echo "$BM_SESSION"
read -s keeps your password off the screen and out of your shell history. If this prints null, the email or password is wrong. Ten failed tries in 15 minutes lock sign-in for a while.
Connect the service
Run this in the same terminal. Fill in your site ID, the two Railway IDs and your domain:
BM_SITE=my-shop
SERVICE_ID=0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b
ENVIRONMENT_ID=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d
read -r -s -p 'Railway token: ' RAILWAY_TOKEN; echo
curl -sS -X PUT "https://api.botmotive.io/v1/sites/$BM_SITE/railway" \
-H "authorization: Bearer $BM_SESSION" \
-H 'content-type: application/json' \
-d "$(jq -n --arg t "$RAILWAY_TOKEN" --arg s "$SERVICE_ID" --arg e "$ENVIRONMENT_ID" --arg d 'example.com' \
'{token: $t, service_id: $s, environment_id: $e, domain: $d}')"
Botmotive checks the token can see the service before it saves anything. On success it prints the connection status, starting with {"railway":{"service_id":....
domain is optional. When it's set, Botmotive reads your robots.txt and sitemap from that domain once a day. Leave it out by deleting --arg d 'example.com' and , domain: $d.
Add a guard to enforce fixes
Add the guard for your framework, with BOTMOTIVE_SITE and BOTMOTIVE_TOKEN set in Railway's service variables:
Railway's edge sets x-real-ip to the visitor's address. The Node guard reads it by default. For Django and Laravel, set BOTMOTIVE_IP_HEADER=x-real-ip.
Settings that matter
First pull. A new connection starts 15 minutes back. Botmotive holds back the most recent minute, because Railway delivers logs a little late.
Redeploys. Botmotive follows new deployments of the service on its own.
Fewer signals. Railway's logs carry the client IP, user agent, method, path, status, bytes and app time. They carry no other request headers and no referer.
Check it worked
Check the connection status:
curl -sS -H "authorization: Bearer $BM_SESSION" "https://api.botmotive.io/v1/sites/$BM_SITE/railway"After a minute or two,
last_pulled_atshould have a value andlast_errorshould benull.Open your site in the dashboard and click the 15m tab.
Once requests arrive, the dashboard says Receiving data with a count of requests so far. Results follow 15 to 30 minutes after the first request, and the dashboard opens on the tab that has them.
Updating and removing
New Railway token. Run the connect step again with the new token. For the same service, Botmotive carries on from where it stopped.
Another service. Run the connect step with the new IDs. A different service starts 15 minutes back.
Removing. Stop the pulls:
curl -sS -X DELETE -H "authorization: Bearer $BM_SESSION" "https://api.botmotive.io/v1/sites/$BM_SITE/railway"It prints
{"disconnected":true}. Then delete the project token in Railway.Signing out. End the session when you're done:
curl -sS -X POST -H "authorization: Bearer $BM_SESSION" https://api.botmotive.io/v1/auth/logout
If something goes wrong
unauthorized. The session token is missing or expired. Get a new one.owners only. Only the site's owner can connect Railway.not found. The site ID is wrong, or you aren't a member of that site.service_id and environment_id must be Railway IDs. Check both IDs are the full 36 characters.Railway rejected the token for that service: .... The token is wrong, or it belongs to another project or environment.last_errorhas a value. Botmotive couldn't pull. The text says why. A revoked Railway token is the usual cause.
For more, see Troubleshooting.