Koji & Regions¶
This page covers two operator jobs: connecting PoracleWeb.NET to Koji, and setting up regions so the region picker works for your users. The region picker is the part most operators get tripped up on, so the relationship between geofences and regions is laid out carefully with diagrams.
What Koji is doing here¶
Koji is the home for your public geofences — the admin-managed areas everyone can subscribe to. PoracleWeb.NET talks to Koji to:
- Read the list of public areas (so users can pick them, and the bot can match on them).
- Read your regions (the folders that group public areas).
- Write a new public area when an admin approves a user submission.
Private user geofences never touch Koji — they live inside PoracleWeb.NET until (and unless) an admin promotes them.
PoracleNG never talks to Koji directly
PoracleWeb.NET is the only thing that talks to Koji. PoracleWeb.NET merges Koji's public areas with the private user areas and serves them as one combined feed. PoracleNG reads that single URL. See Troubleshooting → How the combined feed works.
Connecting PoracleWeb.NET to Koji¶
Set these in your .env file:
.env variable |
What it is | Example |
|---|---|---|
KOJI_API_ADDRESS |
URL of your Koji server | http://koji-host:8080 |
KOJI_BEARER_TOKEN |
Koji API token | your-koji-token |
KOJI_PROJECT_ID |
The numeric Koji project PoracleWeb.NET works in | 1 |
KOJI_PROJECT_NAME |
That project's name (used for the area feed) | MyProject |
The token is read at startup
KOJI_BEARER_TOKEN is read once when PoracleWeb.NET starts. If you change it, restart PoracleWeb.NET for it to take effect.
Then point your PoracleNG bot at PoracleWeb.NET's combined feed (a single URL, not Koji) via its geofence-source setting:
// PoracleNG bot — geofence source
"geofence": {
"path": "http://poracleweb:8082/api/geofence-feed"
}
That's the whole connection. If Koji goes down, PoracleWeb.NET keeps serving the private user geofences on their own, so notifications don't stop dead — see Troubleshooting.
Renames and approvals move the owner's subscriptions¶
When a geofence is renamed, or approved under a different public name, the name in every profile that had it switched on has to change too. PoracleWeb.NET asks PoracleNG to do that across all of the owner's profiles, after telling PoracleNG to reload its geofences (the new name must be loaded first).
- A user's rename is all-or-nothing. If PoracleNG can't move the name, the geofence gets its old name back and the user sees an error saying nothing was changed.
- An approval goes ahead either way, because the geofence is already public in Koji. It tries the move twice. If both attempts fail, the admin sees "Approved, but the owner's areas weren't moved. They can pick the new area on the Areas page.", and the owner picks the public area again from the Areas page.
Forcing a refresh after a change in Koji¶
PoracleWeb.NET caches Koji's public-area list for 5 minutes. A change made directly in the Koji UI won't reach the feed until that expires — which is a problem for provisioning tools that create an area in Koji and then tell PoracleNG to reload: the reload re-reads the stale list, answers {"status":"ok"}, and the new area still isn't selectable.
POST /api/geofence-feed/refresh drops the cached Koji half so the next feed read re-fetches it:
curl -X POST -H "X-Poracle-Secret: $PORACLE_API_SECRET" http://poracleweb:8082/api/geofence-feed/refresh
It answers {"status":"ok"}. Things worth knowing:
- It authenticates with the same secret you already set in
PORACLE_API_SECRET— the one PoracleWeb.NET sends to PoracleNG — passed in anX-Poracle-Secretheader. - It fails closed: with no secret configured there is nothing to compare against, so every request is refused rather than every request allowed.
- It is rate-limited to 20 requests per minute per IP. One refresh per area created is well inside that.
- Reading the feed is unchanged and still needs no secret.
Approving a submission in PoracleWeb.NET already clears the cache, so this endpoint is only for changes made outside PoracleWeb.NET.
How geofences and regions relate in Koji¶
This is the key mental model.
A region is not a special object
Koji only has geofences. A geofence becomes a region simply by having other geofences nested underneath it (children that point to it as their parent).
flowchart TD
Proj[Your Koji project]
Proj --> CO[colorado<br/>★ REGION — has children]
Proj --> CA[california<br/>★ REGION — has children]
Proj --> KC[kansas-city<br/>not a region — no children]
CO --> DEN[denver]
CO --> BOU[boulder]
CA --> SF[san-francisco]
CA --> LA[los-angeles]
style CO fill:#1e88e5,color:#fff
style CA fill:#1e88e5,color:#fff
style KC fill:#bbb,color:#000
So:
- A region = a parent geofence (a geofence that other geofences are nested under).
- The region itself is hidden from the area picker — you don't subscribe to
colorado, you subscribe todenver, which is grouped under Colorado. - A geofence with no children is not a region — it's just a plain selectable area (
kansas-cityabove).
Here's how PoracleWeb.NET decides what counts as a region:
flowchart TD
Start[For each geofence in Koji] --> Q{Does any OTHER geofence<br/>list it as its parent?}
Q -->|Yes| R[It's a REGION<br/>used as a folder]
Q -->|No| N[Not a region<br/>just a plain area]
Setting up regions (the operator how-to)¶
If your users open the "draw a geofence" dialog and the region dropdown is empty (or only shows "All"), it's because your Koji project has no nesting — every geofence is flat, with no parents. Here's how to create regions:
- Create a parent geofence in Koji for each region you want — for example a polygon for the whole state of
colorado, or a metro area likedenver-metro. This is just a normal Koji geofence; nothing special. - Nest your public area geofences under it. In Koji, open each child geofence (e.g.
denver,boulder) and set its parent to the region geofence (colorado). That parent link is the only thing that makes a region. - Done. Reload the geofence page in PoracleWeb.NET (the list refreshes within 5 minutes, or immediately after the next approval). Each parent that now has at least one child shows up as a region, using the parent geofence's display name as the folder label.
flowchart LR
subgraph S1 [Step 1: make a parent]
A1[colorado<br/>no children yet,<br/>not a region]
end
subgraph S2 [Step 2: nest children under it]
B1[colorado — now a REGION]
B1 --> B2[denver]
B1 --> B3[boulder]
end
S1 --> S2
Do you even need regions?¶
No — regions are optional. They are a convenience for grouping public areas and for auto-suggesting a folder when a user draws a shape. If your Koji project is flat and you don't want regions:
- Users can still draw private geofences and use them — the region picker simply hides itself when there are no regions (this fixes the empty-dropdown problem; see Troubleshooting).
- When an admin promotes a geofence, they can leave the region unset, and it becomes an ungrouped public area. You can always organize it into a region later in Koji.
How region names are grouped in the pickers¶
The region and group pickers (Areas, the map's "Jump to region", the draw and approval dialogs) build their headings from the names, split on -. Names that share everything before their last part are listed under that shared part, showing only the last part:
A heading appears only when it covers two or more names. A name with no -, or the only one with its prefix, is listed on its own under its full name, so Downtown, Eastside and US - HI - Oahu each get one line. Search matches the whole name, so typing VA finds Richmond. Areas with no group are listed last as "Ungrouped".
So name regions Country - State - City (or State - City) if you want them nested, and plain names if you don't. Both work. On the Areas page the picker is hidden when there is only one group to choose from.
Koji geofence properties (and how they're used)¶
When PoracleWeb.NET promotes a geofence to a public area, it writes a set of properties onto the Koji geofence. If you create or edit geofences directly in Koji, these are the same properties that matter — and getting userSelectable / displayInMatches wrong is the usual cause of a private area leaking into the bot, or a public area never showing up.
There are two groups. The __-prefixed keys are Koji structural directives (they set Koji's own built-in fields). The rest are custom properties that Koji stores on the geofence and passes through to the bot feed.
Structural directives (the __ keys)¶
| Property | Value PoracleWeb.NET sends | What it does |
|---|---|---|
__name |
the lowercase area name | Koji's internal geofence key — this is the name that ends up in users' area lists and that the bot matches on. Must be lowercase. |
__mode |
unset |
Koji's geofence "mode" marker. PoracleWeb.NET doesn't use modes, so it leaves this unset. |
__projects |
[ <your KOJI_PROJECT_ID> ] |
Which Koji project(s) the geofence belongs to. A geofence must be in your project to appear in the feed. Sending an empty list ([]) removes it from the project — that's how "remove from project" works. |
__parent |
the region's geofence id, or null |
Nests this geofence under a region (see the region relationship). Must be a real geofence id or null — never 0. |
__parent must be null, not 0, for no region
Koji looks up __parent as a real geofence id. Sending 0 makes Koji reject the save with [GEOFENCE]: Does not exist (while still writing the row — a half-broken state). PoracleWeb.NET sends null for a region-less geofence so this works cleanly. If you set parents by hand in Koji, leave it empty rather than 0.
Custom properties (passed through to the bot feed)¶
| Property | Value PoracleWeb.NET sends | What it does |
|---|---|---|
name |
the user-facing display name | The friendly label shown in PoracleWeb.NET's region/area lists. Read back from Koji to label regions. |
group |
the region/category label | The folder a public area is shown under in the bot's area picker. For admin geofences this is resolved from the parent chain. |
parent |
the same region/category label | A duplicate of group that some PoracleNG format serializers read instead of group. (This is the custom parent property — a text label — and is separate from the structural __parent id above.) |
userSelectable |
true when public, false when private |
The visibility switch. true = the area appears in the bot's !area picker. false = hidden. PoracleNG's own area check allows only userSelectable=true areas for non-admins, so PoracleWeb.NET checks a private geofence's name itself and saves it to PoracleNG as a trusted write. PoracleNG stores the name on the profile like any other area. |
displayInMatches |
true when public, false when private |
Whether the area name appears in notification DM text. false keeps private geofence names out of messages. |
For a private user geofence, PoracleWeb.NET never writes any of this to Koji — it serves the geofence from its own feed with userSelectable=false, displayInMatches=false and exemptFromAreaSecurity=true. For an approved (public) geofence, both flags are set to true and the geofence is written into Koji as a normal public area.
exemptFromAreaSecurity matters only on a PoracleNG carrying jfberry/PoracleNG#243 with [area_security] enabled = true. A user's own geofence belongs to no community, so without the flag area security would refuse it wherever a user's areas are checked and prune it when their community changes. The flag exempts the fence from the community check only: it stays hidden from the bot's !area picker and from alert text. PoracleWeb.NET never sets it on a Koji area, and you shouldn't either: an exempt public area can be picked by anyone in any community. Older PoracleNG versions ignore the field.
What PoracleWeb.NET reads back from Koji¶
| Koji endpoint | Properties read | Used for |
|---|---|---|
/api/v1/geofence/reference |
id, name (internal), parent (numeric id) |
Listing every geofence and deriving which ones are regions (a geofence referenced as another's parent). |
/api/v1/geofence/area/{name}?rt=feature |
properties.name, the polygon geometry |
The region's display name and its outline (used for region auto-detection). |
/api/v1/geofence/poracle/{project} |
name, path or multipath, group |
The public-area list merged into the combined feed. |
Areas in more than one piece¶
An area can be several separate shapes under one name: an island and the mainland facing it, or two halves of
a town split by a river. In Koji that's a MultiPolygon. You get one by drawing it that way, or by loading a
fence from your scanner and editing it, which can turn a plain polygon into a MultiPolygon without you
asking for one.
PoracleWeb.NET serves such an area to PoracleNG in PoracleNG's own multipath shape, one ring per piece, and
it's one area everywhere else too: one entry in the area picker, one shape on every map, and one name in
the Discord review card when a submission falls in any of its pieces. A region can be a MultiPolygon as
well, and region auto-detection checks every piece.
Matching ignores holes. PoracleNG checks only the outer edge of each piece, so a lake cut out of an area still counts as inside it. Koji keeps the holes, and PoracleWeb.NET sends them back unchanged whenever it re-saves an area, when taking it out of the project for example.
The feed sends a multi-piece area as multipath with no path key at all. That's the shape PoracleNG's own
geofence list uses, and PoracleJS needs it, because it looks at path first and an empty one would stop it
there.
Before this was supported, a MultiPolygon area was dropped from the feed without a word: it wasn't in the
area list, PoracleNG never loaded it, and nothing matched it. If you have one that went missing, it comes back
the next time PoracleNG reloads its geofences after you upgrade.
Hiding an area from your users¶
Staging fences, test polygons, a region you cover but do not advertise: Admin → Areas lists every area Koji serves and lets you take one off the menu without deleting it.
A hidden area stops appearing in three places at once, because all three read the same flag:
- Areas & places, where users pick their subscriptions
- the delivery scope picker on an individual alarm
- the bot's own
!arealist
You do not need Koji access for this. PoracleWeb.NET is the geofence source Poracle loads, so hiding
serves that fence with userSelectable: false in the feed.
Setting the area private in Koji works too, and now genuinely does: until #885 this site read Koji's
export but hardcoded userSelectable and displayInMatches to true, so a fence an operator had
already made private in Koji was handed to every user as selectable anyway. Both flags are read now.
Areas private in Koji are listed as Private in Koji and their switch is disabled, because clearing a
flag this site did not set would not make them selectable.
Hiding doesn't take anyone off an area
Hiding is immediate for new selections and invisible to matching. Matching never consults
userSelectable (resolveOverride hands a rule's areas to areaOverlap, which compares names against
the fences a spawn fell in), so a profile still carrying a hidden name keeps receiving its alerts.
It stays that way through later saves. The Areas & places page sends back every name the profile already holds, including ones it no longer lists, and PoracleWeb.NET allows a name the profile already has before writing the list to PoracleNG as trusted. An alarm limited to the area keeps it too: the scope picker keeps the areas an alarm already carries, and the area check allows a name already on the rule. A user leaves a hidden area only by removing it from their selection, or by changing the alarm's scope.
If you're hiding a test fence nobody uses, that's all there is to it. If people use it and you need them off it, tell them to remove it.
The list is kept in the hidden_areas site setting. A name you hide that Koji later stops serving is
kept rather than dropped, so a Koji outage does not silently un-hide anything; the page flags those
separately.
displayInMatches is deliberately untouched. Someone still subscribed keeps matching the fence, and
blanking its name out of their alert would make that harder to diagnose rather than easier.
What auto-detection does¶
When a user draws a shape, PoracleWeb.NET tries to guess the region by checking which region's outline the drawn shape falls inside (using the center point of the drawing). If it finds a match, it pre-fills the region for the user. This is purely a convenience — the user can change or clear it, and it only works if your regions have outlines (which they do, since they're real Koji geofences).