Skip to content

Commit

Permalink
Fix slackapi#926 by adding more subtype ones to message event types
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed May 19, 2021
1 parent 5185d7b commit 2e57714
Show file tree
Hide file tree
Showing 2 changed files with 284 additions and 0 deletions.
158 changes: 158 additions & 0 deletions src/types/events/message-events.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// tslint:disable:no-implicit-dependencies
import { assert } from 'chai';
import { BotMessageEvent, MessageEvent } from './message-events';

describe('message event types', () => {
it('should be compatible with bot_message payload', () => {
const payload: BotMessageEvent = {
type: 'message',
subtype: 'bot_message',
bot_id: '',
username: '',
icons: {},
channel: '',
text: '',
blocks: [],
thread_ts: '',
ts: '',
event_ts: '',
channel_type: 'channel',
};
assert.isNotEmpty(payload);
});

it('should be compatible with channel_archive payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_archive',
team: '',
user: '',
channel: '',
channel_type: 'channel',
text: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_join payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_join',
team: '',
user: '',
inviter: '',
channel: '',
channel_type: 'channel',
text: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_leave payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_leave',
team: '',
user: '',
channel: '',
channel_type: 'channel',
text: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_name payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_name',
team: '',
user: '',
name: '',
old_name: '',
channel: '',
channel_type: 'channel',
text: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_posting_permissions payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_posting_permissions',
user: '',
channel: '',
channel_type: 'channel',
text: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_purpose payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_purpose',
user: '',
channel: '',
channel_type: 'channel',
text: '',
purpose: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_topic payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_topic',
user: '',
channel: '',
channel_type: 'channel',
text: '',
topic: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with channel_unarchive payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'channel_unarchive',
team: '',
user: '',
channel: '',
channel_type: 'channel',
text: '',
ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
it('should be compatible with file_share payload', () => {
const payload: MessageEvent = {
type: 'message',
subtype: 'file_share',
user: '',
channel: '',
channel_type: 'channel',
blocks: [],
attachments: [],
files: [],
upload: false,
display_as_bot: false,
parent_user_id: '',
text: '',
ts: '',
thread_ts: '',
event_ts: '',
};
assert.isNotEmpty(payload);
});
});
126 changes: 126 additions & 0 deletions src/types/events/message-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import { MessageAttachment, KnownBlock, Block } from '@slack/types';
export type MessageEvent =
| GenericMessageEvent
| BotMessageEvent
| ChannelArchiveMessageEvent
| ChannelJoinMessageEvent
| ChannelLeaveMessageEvent
| ChannelNameMessageEvent
| ChannelPostingPermissionsMessageEvent
| ChannelPurposeMessageEvent
| ChannelTopicMessageEvent
| ChannelUnarchiveMessageEvent
| EKMAccessDeniedMessageEvent
| FileShareMessageEvent
| MeMessageEvent
| MessageChangedEvent
| MessageDeletedEvent
Expand Down Expand Up @@ -67,6 +76,104 @@ export interface BotMessageEvent {
thread_ts?: string;
}

interface ChannelArchiveMessageEvent {
type: 'message';
subtype: 'channel_archive';
team: string;
user: string;
channel: string;
channel_type: channelTypes;
text: string;
ts: string;
event_ts: string;
}

interface ChannelJoinMessageEvent {
type: 'message';
subtype: 'channel_join';
team: string;
user: string;
inviter: string;
channel: string;
channel_type: channelTypes;
text: string;
ts: string;
event_ts: string;
}

interface ChannelLeaveMessageEvent {
type: 'message';
subtype: 'channel_leave';
team: string;
user: string;
channel: string;
channel_type: channelTypes;
text: string;
ts: string;
event_ts: string;
}

interface ChannelNameMessageEvent {
type: 'message';
subtype: 'channel_name';
team: string;
user: string;
name: string;
old_name: string;
channel: string;
channel_type: channelTypes;
text: string;
ts: string;
event_ts: string;
}

interface ChannelPostingPermissionsMessageEvent {
type: 'message';
subtype: 'channel_posting_permissions';
user: string;
channel: string;
channel_type: channelTypes;
text: string;
ts: string;
event_ts: string;
}

interface ChannelPurposeMessageEvent {
type: 'message';
subtype: 'channel_purpose';
user: string;
channel: string;
channel_type: channelTypes;
text: string;
purpose: string;
ts: string;
event_ts: string;
}

interface ChannelTopicMessageEvent {
type: 'message';
subtype: 'channel_topic';
user: string;
channel: string;
channel_type: channelTypes;
text: string;
topic: string;
ts: string;
event_ts: string;
}

interface ChannelUnarchiveMessageEvent {
type: 'message';
subtype: 'channel_unarchive';
team: string;
user: string;
channel: string;
channel_type: channelTypes;
text: string;
ts: string;
event_ts: string;
}

export interface EKMAccessDeniedMessageEvent {
type: 'message';
subtype: 'ekm_access_denied';
Expand All @@ -78,6 +185,25 @@ export interface EKMAccessDeniedMessageEvent {
user: 'UREVOKEDU';
}

interface FileShareMessageEvent {
type: 'message';
subtype: 'file_share';
text: string;
attachments?: MessageAttachment[];
blocks?: (KnownBlock | Block)[];
files?: File[];
upload?: boolean;
display_as_bot?: boolean;
x_files?: string[];
user: string;
parent_user_id?: string;
ts: string;
thread_ts?: string;
channel: string;
channel_type: channelTypes;
event_ts: string;
}

export interface MeMessageEvent {
type: 'message';
subtype: 'me_message';
Expand Down

0 comments on commit 2e57714

Please sign in to comment.