Skip to content

Commit 0f992d4

Browse files
afgielmatthova
andauthored
[activities] add documentation for get_activity_instance (#6981)
* Add docs for activity instance validation * update to for new endpoint and shape * touch up some stuff advaith noticed * first pass Get Application Activity Instance endpoint * add warning about channel_id and future deprecation * fix url in curl examples * update example in development guide * remove channel_id, add tables for Activity Instance Object, Activity Location Object, Activity Location Kind Enum * cleanup that json * pnpm run fix:tables * :s/activity-instance/activity-instances/g * add Type column to Application Location table --------- Co-authored-by: Matt Hova <[email protected]>
1 parent 98deea8 commit 0f992d4

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

docs/activities/Development_Guides.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ These guides include suggested development practices, SDK commands, and user flo
9494
<Card title="Render Avatars and Names" link="#DOCS_ACTIVITIES_DEVELOPMENT_GUIDES/render-avatars-and-names">
9595
Retrieve and render the usernames and avatars of users connected to your application.
9696
</Card>
97+
<Card title="Preventing Unwanted Activity Sessions" link="#DOCS_ACTIVITIES_DEVELOPMENT_GUIDES/preventing-unwanted-activity-sessions">
98+
Validating activity sessions are via a Discord client before adding them to an instance's session.
99+
</Card>
97100
</Container>
98101

99102
## Assets & Metadata
@@ -887,6 +890,29 @@ This example is being done entirely on the client, however, a more common patter
887890
888891
---
889892
893+
### Preventing unwanted activity sessions
894+
895+
Activities are surfaced through iframes in the Discord app. The activity website itself is publicly reachable at `<application_id>.discordsays.com`. Activities will expect to be able to communicate with Discord's web or mobile client via the Discord SDK's RPC protocol. If a user loads the activity's website in a normal browser, the Discord RPC server will not be present, and the activity will likely fail in some way.
896+
897+
It is theoretically possible for a malicious client to mock Discord's RPC protocol or load one activity website when launching another. Because the activity is loaded inside Discord, the RPC protocol is active, and the activity is none the wiser.
898+
899+
To enable an activity to "lock down" activity access, we encourage utilizing the `get_activity_instance` API, found at `discord.com/api/applications/<application_id>/activity-instances/<instance_id>'`. The route requires a Bot token of the application. It returns a serialized active activity instance for the given application, if found, otherwise it returns a 404. Here are two example responses:
900+
901+
```javascript
902+
curl https://discord.com/api/applications/1215413995645968394/activity-instances/i-1234567890-gc-912952092627435520-912954213460484116 -H 'Authorization: Bot <bot token>'
903+
{"message": "404: Not Found", "code": 0}
904+
905+
curl https://discord.com/api/applications/1215413995645968394/activity-instances/i-1276580072400224306-gc-912952092627435520-912954213460484116 -H 'Authorization: Bot <bot token>'
906+
{"application_id":"1215413995645968394","instance_id":"i-1276580072400224306-gc-912952092627435520-912954213460484116","launch_id":"1276580072400224306","location":{"id":"gc-912952092627435520-912954213460484116","kind":"gc","channel_id":"912954213460484116","guild_id":"912952092627435520"},"users":["205519959982473217"]}
907+
```
908+
909+
With this API, the activity's backend can verify that a client is in fact in an instance of that activity before allowing the client to participate in any meaningful gameplay. How an activity implements "session verification" is left to the developer's discretion. The solution can be as granular as gating specific features or as binary as not returning the activity HTML except for valid sessions.
910+
911+
In the below flow diagram, we show how the server can deliver the activity website, only for valid users in a valid activity instance:
912+
![application-test-mode-prod](activities/activity-instance-validation.jpg)
913+
914+
---
915+
890916
### Setting Up Activity Metadata
891917
892918
The Activity Shelf is where users can see what Activities can be played. It has various metadata and art assets that can be configured.

docs/resources/Application.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,56 @@ Edit properties of the app associated with the requesting bot user. Only propert
236236

237237
\* Only limited intent flags (`GATEWAY_PRESENCE_LIMITED`, `GATEWAY_GUILD_MEMBERS_LIMITED`, and `GATEWAY_MESSAGE_CONTENT_LIMITED`) can be updated via the API.
238238

239-
\*\* To update an Interactions endpoint URL via the API, the URL must be valid according to the [Receiving an Interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/receiving-an-interaction) documentation.
239+
\*\* To update an Interactions endpoint URL via the API, the URL must be valid according to the [Receiving an Interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/receiving-an-interaction) documentation.
240+
241+
## Get Application Activity Instance % GET /applications/{application.id#DOCS_RESOURCES_APPLICATION/application-object}/activity-instances/{instance_id}
242+
243+
Returns a serialized activity instance, if it exists. Useful for [preventing unwanted activity sessions](#DOCS_ACTIVITIES_DEVELOPMENT_GUIDES/preventing-unwanted-activity-sessions).
244+
245+
246+
###### Example Activity Instance
247+
248+
```json
249+
{
250+
"application_id": "1215413995645968394",
251+
"instance_id": "i-1276580072400224306-gc-912952092627435520-912954213460484116",
252+
"launch_id": "1276580072400224306",
253+
"location": {
254+
"id": "gc-912952092627435520-912954213460484116",
255+
"kind": "gc",
256+
"channel_id": "912954213460484116",
257+
"guild_id": "912952092627435520"
258+
},
259+
"users": ["205519959982473217"],
260+
}
261+
```
262+
263+
###### Activity Instance Object
264+
265+
| Field | Type | Description |
266+
|----------------|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
267+
| application_id | snowflake | [Application](#DOCS_RESOURCES_APPLICATION/application-object) ID |
268+
| instance_id | string | Activity [Instance](#DOCS_ACTIVITIES_DEVELOPMENT_GUIDES/activity-instance-management) ID |
269+
| launch_id | snowflake | Unique identifier for the launch |
270+
| location | [Activity Location](#DOCS_RESOURCES_APPLICATION/get-application-activity-instance-activity-location-object) | The Location the instance is runnning in |
271+
| users | array of snowflakes, [user](#DOCS_RESOURCES_USER/user-object) ids | The IDs of the Users currently connected to the instance |
272+
273+
274+
275+
###### Activity Location Object
276+
277+
The Activity Location is an object that describes the location in which an activity instance is running.
278+
279+
| Field | Type | Description |
280+
|------------|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
281+
| id | string | The unique identifier for the location |
282+
| kind | [Activity Location Kind Enum](#DOCS_RESOURCES_APPLICATION/get-application-activity-instance-activity-location-kind-enum) | Enum describing kind of location |
283+
| channel_id | snowflake | The id of the [Channel](#DOCS_RESOURCES_CHANNEL/channel-object) |
284+
| guild_id? | ?snowflake | The id of the [Guild](#DOCS_RESOURCES_GUILD/guild-object) |
285+
286+
###### Activity Location Kind Enum
287+
288+
| Enum | Description |
289+
|------|--------------------------------------------------------|
290+
| 'gc' | The Location is a Guild Channel |
291+
| 'pc' | The Location is a Private Channel, such as a DM or GDM |
156 KB
Loading

0 commit comments

Comments
 (0)