Skip to content

Commit

Permalink
feat: adding event payloads from bolt-js as a starting point (#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
filmaj authored Aug 30, 2024
1 parent be8cb4e commit d857511
Show file tree
Hide file tree
Showing 29 changed files with 2,013 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/types/src/common/bot-profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface BotProfile {
id: string;
name: string;
app_id: string;
team_id: string;
icons: {
[size: string]: string;
};
updated: number;
deleted: boolean;
}
5 changes: 5 additions & 0 deletions packages/types/src/common/status-emoji-display-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface StatusEmojiDisplayInfo {
emoji_name?: string;
display_alias?: string;
display_url?: string;
}
166 changes: 166 additions & 0 deletions packages/types/src/events/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { Block, KnownBlock } from '../block-kit/blocks';
import { BotProfile } from '../common/bot-profile';
import { MessageAttachment } from '../message-attachments';
import { View } from '../views';

export interface AppRequestedEvent {
type: 'app_requested';
app_request: {
id: string;
app: {
id: string;
name: string;
description: string;
help_url: string;
privacy_policy_url: string;
app_homepage_url: string;
app_directory_url: string;
is_app_directory_approved: boolean;
is_internal: boolean;
additional_info: string;
icons?: {
image_32?: string;
image_36?: string;
image_48?: string;
image_64?: string;
image_72?: string;
image_96?: string;
image_128?: string;
image_192?: string;
image_512?: string;
image_1024?: string;
image_original?: string;
}
};
};
previous_resolution: {
status: 'approved' | 'restricted';
scopes: {
name: string;
description: string;
is_dangerous: boolean;
token_type: 'bot' | 'user' | 'app' | null;
};
} | null;
is_user_app_collaborator: boolean;
user: {
id: string;
name: string;
email: string;
};
team: {
id: string;
name: string;
domain: string;
};
scopes: {
name: string;
description: string;
is_dangerous: boolean;
token_type: 'bot' | 'user' | 'app' | null;
};
message: string;
date_created: number;
}

export interface AppHomeOpenedEvent {
type: 'app_home_opened';
user: string;
channel: string;
tab?: 'home' | 'messages';
view?: View;
event_ts: string;
}

export interface AppInstalledEvent {
type: 'app_installed';
app_id: string;
app_name: string;
app_owner_id: string;
user_id: string;
team_id: string;
team_domain: string;
event_ts: string;
}

export interface AppDeletedEvent {
type: 'app_deleted';
app_id: string;
app_name: string;
app_owner_id: string;
team_id: string;
team_domain: string;
event_ts: string;
}

export interface AppUninstalledTeamEvent {
type: 'app_uninstalled_team';
app_id: string;
app_name: string;
app_owner_id: string;
team_id: string;
team_domain: string;
user_id: string;
event_ts: string;
}

// TODO: this is essentially the same as the `message` event, except for the type and that this uses `event_ts` instead
// of `ts`
export interface AppMentionEvent {
type: 'app_mention';
subtype?: string;
bot_id?: string;
bot_profile?: BotProfile;
username?: string;
team?: string;
// user_team, source_team, and user_profile
// can exist when the user who mentioned this bot is in a different workspace/org
user_team?: string;
source_team?: string;
user_profile?: {
name: string;
first_name: string;
real_name: string;
display_name: string;
team: string;
is_restricted?: boolean;
is_ultra_restricted?: boolean;
avatar_hash?: string;
image_72?: string;
};
user?: string;
text: string;
attachments?: MessageAttachment[];
blocks?: (KnownBlock | Block)[];
// TODO: Add more properties once the types library has a file object definition
files?: { id: string }[];
upload?: boolean;
display_as_bot?: boolean;
edited?: {
user: string;
ts: string;
};
ts: string;
channel: string;
event_ts: string;
thread_ts?: string;
client_msg_id?: string;
}

export interface AppRateLimitedEvent {
type: 'app_rate_limited';
token: string;
team_id: string;
minute_rate_limited: number;
api_app_id: string;
}

// TODO: this event doesn't use the envelope. write test cases to make sure its works without breaking, and figure out
// what exceptions need to be made to the related types to make this work
// https://api.slack.com/events/app_rate_limited
// export interface AppRateLimitedEvent {
// }

export interface AppUninstalledEvent {
type: 'app_uninstalled';
}
7 changes: 7 additions & 0 deletions packages/types/src/events/call.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface CallRejectedEvent {
type: 'call_rejected';
call_id: string;
user_id: string;
channel_id: string;
external_unique_id: string;
}
93 changes: 93 additions & 0 deletions packages/types/src/events/channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
export interface ChannelArchiveEvent {
type: 'channel_archive';
channel: string;
user: string;
is_moved?: number;
event_ts: string;
}

export interface ChannelCreatedEvent {
type: 'channel_created';
event_ts: string;
channel: {
id: string;
is_channel: boolean;
name: string;
name_normalized: string;
created: number;
creator: string; // user ID
is_shared: boolean;
is_org_shared: boolean;
context_team_id: string,
is_archived: boolean;
is_frozen: boolean,
is_general: boolean,
is_group: boolean,
is_private: boolean,
is_ext_shared: boolean,
is_im: boolean,
is_mpim: boolean,
is_pending_ext_shared: boolean,
};
}

export interface ChannelDeletedEvent {
type: 'channel_deleted';
channel: string;
}

export interface ChannelHistoryChangedEvent {
type: 'channel_history_changed';
latest: string;
ts: string;
event_ts: string;
}

export interface ChannelIDChangedEvent {
type: 'channel_id_changed';
old_channel_id: string;
new_channel_id: string;
event_ts: string;
}

export interface ChannelLeftEvent {
type: 'channel_left';
channel: string;
actor_id: string;
event_ts: string;
}

export interface ChannelRenameEvent {
type: 'channel_rename';
channel: {
id: string;
name: string;
name_normalized: string;
created: number;
is_channel: boolean;
is_mpim: boolean;
};
event_ts: string;
}

export interface ChannelSharedEvent {
type: 'channel_shared';
connected_team_id: string;
channel: string;
event_ts: string;
}

export interface ChannelUnarchiveEvent {
type: 'channel_unarchive';
channel: string;
user: string;
event_ts: string;
}

export interface ChannelUnsharedEvent {
type: 'channel_unshared';
previously_connected_team_id: string;
channel: string;
is_ext_shared: boolean;
event_ts: string;
}
24 changes: 24 additions & 0 deletions packages/types/src/events/dnd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface DNDUpdatedEvent {
type: 'dnd_updated';
user: string;
dnd_status: {
dnd_enabled: boolean;
next_dnd_start_ts: number;
next_dnd_end_ts: number;
snooze_enabled: boolean;
snooze_endtime: number;
snooze_remaining: number;
};
event_ts: string;
}

export interface DNDUpdatedUserEvent {
type: 'dnd_updated_user';
user: string;
dnd_status: {
dnd_enabled: boolean;
next_dnd_start_ts: number;
next_dnd_end_ts: number;
};
event_ts: string;
}
5 changes: 5 additions & 0 deletions packages/types/src/events/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface EmailDomainChangedEvent {
type: 'email_domain_changed';
email_domain: string;
event_ts: string;
}
11 changes: 11 additions & 0 deletions packages/types/src/events/emoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// TODO: breaking change: this should probably be broken into its two subtypes
export interface EmojiChangedEvent {
type: 'emoji_changed';
subtype: 'add' | 'remove' | 'rename';
names?: string[]; // only for remove
name?: string; // only for add
value?: string; // only for add
old_name?: string;
new_name?: string;
event_ts: string;
}
67 changes: 67 additions & 0 deletions packages/types/src/events/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// NOTE: `file_comment_added` and `file_comment_edited` are left out because they are discontinued

export interface FileChangeEvent {
type: 'file_change';
file_id: string;
file: {
id: string;
};
}

export interface FileCommentDeletedEvent {
type: 'file_comment_deleted';
comment: string; // this is an ID
file_id: string;
file: {
id: string;
};
}

export interface FileCreatedEvent {
type: 'file_created';
file_id: string;
user_id: string;
file: {
id: string;
};
event_ts: string;
}

export interface FileDeletedEvent {
type: 'file_deleted';
file_id: string;
channel_ids?: string[];
event_ts: string;
}

export interface FilePublicEvent {
type: 'file_public';
file_id: string;
user_id: string;
file: {
id: string;
};
event_ts: string;
}

export interface FileSharedEvent {
type: 'file_shared';
file_id: string;
user_id: string;
file: {
id: string;
};
channel_id: string;
event_ts: string;
}

export interface FileUnsharedEvent {
type: 'file_unshared';
file_id: string;
user_id: string;
file: {
id: string;
};
channel_id: string;
event_ts: string;
}
Loading

0 comments on commit d857511

Please sign in to comment.