Skip to content

Commit

Permalink
updated interactive payloads for org apps
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengill committed Nov 25, 2020
1 parent 8b803f5 commit 9e89cee
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 22 deletions.
52 changes: 38 additions & 14 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface Authorize {

/** Authorization function inputs - authenticated data about an event for the authorization function */
export interface AuthorizeSourceData {
teamId: string;
teamId: string | undefined;
enterpriseId?: string;
userId?: string;
conversationId?: string;
Expand Down Expand Up @@ -631,10 +631,10 @@ export default class App {
let { client } = this;
const token = selectToken(context);
if (token !== undefined) {
let pool = this.clients[source.teamId];
let pool = this.clients[source.teamId!];
if (pool === undefined) {
// eslint-disable-next-line no-multi-assign
pool = this.clients[source.teamId] = new WebClientPool();
pool = this.clients[source.teamId!] = new WebClientPool();
}
client = pool.getOrCreate(token, this.clientOptions);
}
Expand Down Expand Up @@ -717,30 +717,54 @@ function buildSource(
teamId:
type === IncomingEventType.Event || type === IncomingEventType.Command
? ((body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).team_id as string)
: type === IncomingEventType.Action ||
type === IncomingEventType.Options ||
type === IncomingEventType.ViewAction ||
type === IncomingEventType.Shortcut
: (type === IncomingEventType.Action ||
type === IncomingEventType.Options ||
type === IncomingEventType.ViewAction ||
type === IncomingEventType.Shortcut) &&
body.team !== null
? ((body as (
| SlackActionMiddlewareArgs
| SlackOptionsMiddlewareArgs
| SlackViewMiddlewareArgs
| SlackShortcutMiddlewareArgs
)['body']).team!.id as string)
: (type === IncomingEventType.Action ||
type === IncomingEventType.Options ||
type === IncomingEventType.ViewAction ||
type === IncomingEventType.Shortcut) &&
body.user !== undefined
? ((body as (
| SlackActionMiddlewareArgs
| SlackOptionsMiddlewareArgs
| SlackViewMiddlewareArgs
| SlackShortcutMiddlewareArgs
)['body']).team.id as string)
: assertNever(type),
)['body']).user.team_id as string)
: undefined,
enterpriseId:
type === IncomingEventType.Event || type === IncomingEventType.Command
? ((body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).enterprise_id as string)
: type === IncomingEventType.Action ||
type === IncomingEventType.Options ||
type === IncomingEventType.ViewAction ||
type === IncomingEventType.Shortcut
: (type === IncomingEventType.Action ||
type === IncomingEventType.Options ||
type === IncomingEventType.ViewAction ||
type === IncomingEventType.Shortcut) &&
body.team !== null
? ((body as (
| SlackActionMiddlewareArgs
| SlackOptionsMiddlewareArgs
| SlackViewMiddlewareArgs
| SlackShortcutMiddlewareArgs
)['body']).team!.enterprise_id as string)
: (type === IncomingEventType.Action ||
type === IncomingEventType.Options ||
type === IncomingEventType.ViewAction ||
type === IncomingEventType.Shortcut) &&
body.enterprise !== undefined
? ((body as (
| SlackActionMiddlewareArgs
| SlackOptionsMiddlewareArgs
| SlackViewMiddlewareArgs
| SlackShortcutMiddlewareArgs
)['body']).team.enterprise_id as string)
)['body']).enterprise!.id as string)
: undefined,
userId:
type === IncomingEventType.Event
Expand Down
10 changes: 9 additions & 1 deletion src/types/actions/block-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export interface BlockAction<ElementAction extends BasicElementAction = BlockEle
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
user: {
id: string;
name: string;
Expand Down Expand Up @@ -237,6 +237,14 @@ export interface BlockAction<ElementAction extends BasicElementAction = BlockEle

// this appears in the block_suggestions schema, but we're not sure when its present or what its type would be
app_unfurl?: any;

// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};

}

/*
Expand Down
9 changes: 8 additions & 1 deletion src/types/actions/dialog-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface DialogSubmitAction {
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
user: {
id: string;
name: string;
Expand All @@ -26,6 +26,13 @@ export interface DialogSubmitAction {
action_ts: string;
token: string;
response_url: string;

// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/types/actions/interactive-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface InteractiveMessage<Action extends InteractiveAction = Interacti
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
user: {
id: string;
name: string;
Expand All @@ -59,6 +59,13 @@ export interface InteractiveMessage<Action extends InteractiveAction = Interacti
message_ts?: string;
// NOTE: the original_message is not available from ephemeral messages
original_message?: { [key: string]: string };

// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}

/*
Expand Down
9 changes: 8 additions & 1 deletion src/types/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface OptionsRequest<Source extends OptionsSource = OptionsSource> ex
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
channel?: {
id: string;
name: string;
Expand All @@ -52,6 +52,13 @@ export interface OptionsRequest<Source extends OptionsSource = OptionsSource> ex

// this appears in the block_suggestions schema, but we're not sure when its present or what its type would be
app_unfurl?: any;

// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/types/shortcuts/global-shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ export interface GlobalShortcut {
username: string;
team_id: string;
};
// team is null for org apps shortcut payload
team: {
id: string;
domain: string;
enterprise_id?: string;
enterprise_name?: string;
};
} | null;
token: string;
action_ts: string;

// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}
10 changes: 9 additions & 1 deletion src/types/shortcuts/message-shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface MessageShortcut {
id: string;
name: string;
team_id?: string; // undocumented
username?: string; // shows up on org app msg actions
};
channel: {
id: string;
Expand All @@ -31,7 +32,14 @@ export interface MessageShortcut {
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
token: string;
action_ts: string; // undocumented

// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}
16 changes: 14 additions & 2 deletions src/types/view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface ViewSubmitAction {
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
user: {
id: string;
name: string;
Expand All @@ -48,6 +48,12 @@ export interface ViewSubmitAction {
view: ViewOutput;
api_app_id: string;
token: string;
// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}

/**
Expand All @@ -62,7 +68,7 @@ export interface ViewClosedAction {
domain: string;
enterprise_id?: string; // undocumented
enterprise_name?: string; // undocumented
};
} | null;
user: {
id: string;
name: string;
Expand All @@ -72,6 +78,12 @@ export interface ViewClosedAction {
api_app_id: string;
token: string;
is_cleared: boolean;
// exists for enterprise installs
is_enterprise_install?: boolean;
enterprise?: {
id: string;
name: string;
};
}

/**
Expand Down

0 comments on commit 9e89cee

Please sign in to comment.