-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: details on custom event ids and event versions
- Loading branch information
1 parent
5fb8fae
commit 603a2e9
Showing
3 changed files
with
150 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Event Version 1 | ||
|
||
## Event object | ||
|
||
The `event` object is really a [`user`](user.md) object, with one exception; `event.User` and associated fields are optional. Whether or not an `event.User` exists in the `event` is up to the Skill that emits it. For core and 99% of skills, you can expect `event.User` and it's associated fields to exist. Each skill _should_ document the events they `emit`, so you won't be guessing. In fact, at the time of this writing, there is not a single case where a `event.User` is not provided. | ||
|
||
```js | ||
{ | ||
Location: Location, // required | ||
User: User, // optional | ||
createdAt: Date, // date the guest joined the location (optional) | ||
updatedAt: Date, // date the guest changed their subscription to the location (optional) | ||
role: String, // owner|teammate|guest (optional) | ||
status: String, // offline|online (optional) | ||
visits: Number, // how many visits to this location (optional) | ||
lastRecordedVisit: Date, // when they last visited the shop (optional) | ||
payload: Object // data the skill or core is passing on (optional) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Event Version 2 | ||
|
||
The latest event version which supports Skill Views. | ||
|
||
## Event Object | ||
|
||
The incoming event is automatically processed and _might_ contain any (or none) of: | ||
|
||
* `userId` - The id of the User associated with this event | ||
|
||
* `locationId` - The id of the Location associated with this event | ||
|
||
* `organizationId` - The id of the Organization associated with this event | ||
|
||
If these ids are detected, a call is made to the Core API to get the data which are then attached to `ctx.auth` | ||
|
||
The data that is fetched and attached to `ctx.auth` is based on [your skill's config/auth.js file](https://github.com/sprucelabsai/workspace.sprucebot-skills-kit/blob/dev/packages/spruce-skill/config/auth.js). | ||
|
||
In practice your incoming event will look like: | ||
|
||
```js | ||
const { event, auth } = ctx | ||
// "payload" is the data emitted with the event | ||
// "eventId" is a unique id associated with this event | ||
// "retryId" is only defined if this event is being retried | ||
// "name" is the event name: 'did-enter' for example | ||
const { payload, eventId, retryId, name } = event | ||
|
||
let User | ||
let Location | ||
let Organization | ||
if (auth) { // auth may not be defined | ||
User = auth.User // might not be defined | ||
Location = auth.Location // might not be defined | ||
Organization = auth.Organization // might not be defined | ||
} | ||
|
||
// Handle the event... | ||
``` |