Commit 72790290 authored by Tim Kinnane's avatar Tim Kinnane

feat(actions): Add support and test for attachment actions

- Add interface for actions
- Include fix for log consistency
parent 3c9b9910
......@@ -36,20 +36,20 @@ FN:218,(anonymous_42)
FN:218,(anonymous_43)
FNF:34
FNH:16
FNDA:63,loggedIn
FNDA:48,getQueryString
FNDA:60,(anonymous_9)
FNDA:65,loggedIn
FNDA:50,getQueryString
FNDA:66,(anonymous_9)
FNDA:12,setAuth
FNDA:79,getHeaders
FNDA:81,getHeaders
FNDA:15,clearHeaders
FNDA:81,success
FNDA:83,success
FNDA:31,post
FNDA:31,(anonymous_16)
FNDA:31,(anonymous_17)
FNDA:0,(anonymous_18)
FNDA:45,get
FNDA:45,(anonymous_21)
FNDA:45,(anonymous_22)
FNDA:47,get
FNDA:47,(anonymous_21)
FNDA:47,(anonymous_22)
FNDA:0,(anonymous_23)
FNDA:26,login
FNDA:25,logout
......@@ -75,30 +75,30 @@ DA:2,1
DA:3,1
DA:17,1
DA:25,1
DA:26,63
DA:26,65
DA:30,1
DA:31,1
DA:37,1
DA:42,1
DA:43,48
DA:44,34
DA:45,60
DA:48,60
DA:43,50
DA:44,36
DA:45,66
DA:48,66
DA:53,1
DA:54,1
DA:57,1
DA:58,12
DA:59,12
DA:63,1
DA:64,79
DA:65,65
DA:64,81
DA:65,67
DA:70,1
DA:72,64
DA:72,66
DA:76,1
DA:77,15
DA:78,15
DA:82,1
DA:83,81
DA:83,83
DA:104,1
DA:110,31
DA:111,31
......@@ -115,19 +115,19 @@ DA:122,31
DA:124,0
DA:125,0
DA:136,1
DA:142,45
DA:143,45
DA:144,45
DA:145,45
DA:146,45
DA:147,45
DA:148,45
DA:149,45
DA:150,45
DA:151,45
DA:142,47
DA:143,47
DA:144,47
DA:145,47
DA:146,47
DA:147,47
DA:148,47
DA:149,47
DA:150,47
DA:151,47
DA:152,0
DA:154,45
DA:155,45
DA:154,47
DA:155,47
DA:157,0
DA:166,1
DA:170,26
......@@ -164,30 +164,30 @@ LH:77
BRDA:38,0,0,0
BRDA:38,0,1,1
BRDA:43,1,0,14
BRDA:43,1,1,34
BRDA:43,2,0,48
BRDA:43,2,1,36
BRDA:43,2,2,36
BRDA:43,1,1,36
BRDA:43,2,0,50
BRDA:43,2,1,38
BRDA:43,2,2,38
BRDA:46,3,0,3
BRDA:46,3,1,57
BRDA:46,3,1,63
BRDA:63,4,0,1
BRDA:64,5,0,14
BRDA:64,5,1,65
BRDA:64,5,1,67
BRDA:65,6,0,1
BRDA:65,6,1,64
BRDA:66,7,0,65
BRDA:66,7,1,64
BRDA:66,7,2,64
BRDA:66,7,3,64
BRDA:92,8,0,79
BRDA:65,6,1,66
BRDA:66,7,0,67
BRDA:66,7,1,66
BRDA:66,7,2,66
BRDA:66,7,3,66
BRDA:92,8,0,81
BRDA:92,8,1,2
BRDA:85,9,0,81
BRDA:85,9,1,81
BRDA:85,9,2,55
BRDA:85,9,3,80
BRDA:85,9,0,83
BRDA:85,9,1,83
BRDA:85,9,2,57
BRDA:85,9,3,82
BRDA:85,9,4,26
BRDA:85,9,5,55
BRDA:85,9,6,53
BRDA:85,9,5,57
BRDA:85,9,6,55
BRDA:85,9,7,2
BRDA:85,9,8,0
BRDA:85,9,9,0
......@@ -200,15 +200,15 @@ BRDA:116,13,0,0
BRDA:116,13,1,31
BRDA:117,14,0,0
BRDA:117,14,1,31
BRDA:139,15,0,15
BRDA:139,15,0,17
BRDA:144,16,0,1
BRDA:144,16,1,44
BRDA:144,17,0,45
BRDA:144,17,1,44
BRDA:144,16,1,46
BRDA:144,17,0,47
BRDA:144,17,1,46
BRDA:149,18,0,0
BRDA:149,18,1,45
BRDA:149,18,1,47
BRDA:150,19,0,0
BRDA:150,19,1,45
BRDA:150,19,1,47
BRDA:166,20,0,6
BRDA:171,21,0,19
BRDA:171,21,1,7
......@@ -294,9 +294,9 @@ FNDA:33,(anonymous_14)
FNDA:1,disconnect
FNDA:1,(anonymous_16)
FNDA:37,setupMethodCache
FNDA:22,asyncCall
FNDA:23,asyncCall
FNDA:0,(anonymous_19)
FNDA:22,(anonymous_20)
FNDA:23,(anonymous_20)
FNDA:1,callMethod
FNDA:13,cacheCall
FNDA:0,(anonymous_23)
......@@ -315,7 +315,7 @@ FNDA:8,(anonymous_35)
FNDA:15,subscribeToMessages
FNDA:15,(anonymous_37)
FNDA:12,reactToMessages
FNDA:149,(anonymous_39)
FNDA:151,(anonymous_39)
FNDA:10,respondToMessages
FNDA:0,(anonymous_41)
FNDA:40,(anonymous_42)
......@@ -329,7 +329,7 @@ FNDA:0,leaveRoom
FNDA:2,joinRooms
FNDA:4,(anonymous_53)
FNDA:14,prepareMessage
FNDA:14,sendMessage
FNDA:15,sendMessage
FNDA:8,sendToRoomId
FNDA:6,(anonymous_57)
FNDA:2,sendToRoom
......@@ -383,13 +383,13 @@ DA:151,37
DA:152,37
DA:160,37
DA:171,1
DA:172,22
DA:173,22
DA:174,22
DA:172,23
DA:173,23
DA:174,23
DA:176,0
DA:177,0
DA:180,22
DA:183,22
DA:180,23
DA:183,23
DA:194,1
DA:195,1
DA:205,1
......@@ -433,12 +433,12 @@ DA:307,15
DA:334,1
DA:335,12
DA:337,12
DA:338,149
DA:339,149
DA:340,149
DA:341,149
DA:342,79
DA:343,79
DA:338,151
DA:339,151
DA:340,151
DA:341,151
DA:342,81
DA:343,81
DA:345,70
DA:348,0
DA:362,1
......@@ -494,7 +494,7 @@ DA:487,14
DA:488,14
DA:489,14
DA:496,1
DA:497,14
DA:497,15
DA:509,1
DA:513,8
DA:514,5
......@@ -519,9 +519,9 @@ BRDA:123,2,0,37
BRDA:123,2,1,0
BRDA:128,3,0,2
BRDA:128,3,1,31
BRDA:172,4,0,20
BRDA:172,4,0,21
BRDA:172,4,1,2
BRDA:181,5,0,15
BRDA:181,5,0,16
BRDA:181,5,1,7
BRDA:196,6,0,1
BRDA:196,6,1,0
......@@ -534,11 +534,11 @@ BRDA:239,10,0,28
BRDA:239,10,1,28
BRDA:287,11,0,0
BRDA:287,11,1,8
BRDA:339,12,0,149
BRDA:339,12,0,151
BRDA:339,12,1,0
BRDA:339,13,0,149
BRDA:339,13,1,149
BRDA:341,14,0,79
BRDA:339,13,0,151
BRDA:339,13,1,151
BRDA:341,14,0,81
BRDA:341,14,1,70
BRDA:364,15,0,1
BRDA:372,16,0,1
......@@ -606,8 +606,8 @@ FNDA:0,(anonymous_3)
FNDA:0,(anonymous_4)
FNDA:2,replaceLog
FNDA:2,silence
FNDA:325,(anonymous_7)
FNDA:311,(anonymous_8)
FNDA:330,(anonymous_7)
FNDA:314,(anonymous_8)
FNDA:0,(anonymous_9)
FNDA:0,(anonymous_10)
FNDA:0,(anonymous_11)
......@@ -619,8 +619,8 @@ DA:18,0
DA:22,1
DA:25,2
DA:29,2
DA:30,325
DA:31,311
DA:30,330
DA:31,314
DA:32,0
DA:33,0
DA:34,0
......@@ -724,7 +724,7 @@ SF:/Volumes/x/code/rocketchat/Rocket.Chat.js.SDK/src/lib/settings.ts
FN:16,(anonymous_0)
FNF:1
FNH:1
FNDA:3,(anonymous_0)
FNDA:4,(anonymous_0)
DA:3,9
DA:4,9
DA:5,9
......@@ -732,7 +732,7 @@ DA:8,9
DA:9,9
DA:12,9
DA:15,9
DA:16,3
DA:16,4
DA:18,9
DA:19,9
DA:20,9
......@@ -745,7 +745,7 @@ DA:30,9
LF:17
LH:17
BRDA:3,0,0,9
BRDA:3,0,1,9
BRDA:3,0,1,0
BRDA:4,1,0,9
BRDA:4,1,1,9
BRDA:8,2,0,9
......@@ -756,9 +756,9 @@ BRDA:10,4,0,2
BRDA:10,4,1,0
BRDA:11,5,0,7
BRDA:11,5,1,4
BRDA:16,6,0,2
BRDA:16,6,1,7
BRDA:16,7,0,2
BRDA:16,6,0,3
BRDA:16,6,1,6
BRDA:16,7,0,3
BRDA:16,7,1,0
BRDA:18,8,0,9
BRDA:18,8,1,8
......@@ -779,5 +779,5 @@ BRDA:29,15,1,9
BRDA:30,16,0,9
BRDA:30,16,1,9
BRF:34
BRH:32
BRH:31
end_of_record
......@@ -11,29 +11,21 @@ export interface IMessage {
bot?: any;
urls?: string[];
mentions?: string[];
reactions?: {
[emoji: string]: {
usernames: string[];
};
};
location?: {
type: string;
coordinates: string[];
};
attachments?: IAttachment[];
attachments?: IMessageAttachment[];
reactions?: IMessageReaction;
location?: IMessageLocation;
u?: IUser;
editedBy?: IUser;
editedAt?: Date;
editedBy?: {
_id: string;
username: string;
};
u?: {
_id: string;
username: string;
name: string;
};
}
export interface IAttachment {
export interface IUser {
_id: string;
username: string;
name?: string;
}
export interface IMessageAttachment {
fields?: IAttachmentField[];
actions?: IMessageAction[];
color?: string;
text?: string;
ts?: string;
......@@ -55,3 +47,22 @@ export interface IAttachmentField {
title?: string;
value?: string;
}
export interface IMessageAction {
type?: string;
text?: string;
url?: string;
image_url?: string;
is_webview?: boolean;
webview_height_ratio?: string;
msg?: string;
msg_in_chat_window?: boolean;
}
export interface IMessageLocation {
type: string;
coordinates: string[];
}
export interface IMessageReaction {
[emoji: string]: {
usernames: string[];
};
}
{"version":3,"file":"messageInterfaces.js","sourceRoot":"","sources":["../../src/config/messageInterfaces.ts"],"names":[],"mappings":";AAAA,8DAA8D","sourcesContent":["/** @todo contribute these to @types/rocketchat and require */\n\nexport interface IMessage {\n rid: string | null // room ID\n _id?: string // generated by Random.id()\n t?: string // type e.g. rm\n msg?: string // text content\n alias?: string // ??\n emoji?: string // emoji to use as avatar\n avatar?: string // url\n groupable?: boolean // ?\n bot?: any // integration details\n urls?: string[] // ?\n mentions?: string[] // ?\n reactions?: { [emoji: string]: { usernames: string[] } } // emoji: [usernames]\n location?: {\n type: string // e.g. Point\n coordinates: string[] // longitude latitude\n }\n attachments?: IAttachment[]\n editedAt?: Date\n editedBy?: {\n _id: string\n username: string\n }\n u?: { // the user who sent the message\n _id: string\n username: string\n name: string\n }\n}\n\nexport interface IAttachment {\n fields?: IAttachmentField[]\n color?: string\n text?: string\n ts?: string\n thumb_url?: string\n message_link?: string\n collapsed?: boolean\n author_name?: string\n author_link?: string\n author_icon?: string\n title?: string\n title_link?: string\n title_link_download?: string\n image_url?: string\n audio_url?: string\n video_url?: string\n}\n\nexport interface IAttachmentField {\n short?: boolean\n title?: string\n value?: string\n}\n"]}
\ No newline at end of file
{"version":3,"file":"messageInterfaces.js","sourceRoot":"","sources":["../../src/config/messageInterfaces.ts"],"names":[],"mappings":";AAAA,8DAA8D","sourcesContent":["/** @todo contribute these to @types/rocketchat and require */\n\nexport interface IMessage {\n rid: string | null // room ID\n _id?: string // generated by Random.id()\n t?: string // type e.g. rm\n msg?: string // text content\n alias?: string // ??\n emoji?: string // emoji to use as avatar\n avatar?: string // url\n groupable?: boolean // ?\n bot?: any // integration details\n urls?: string[] // ?\n mentions?: string[] // ?\n attachments?: IMessageAttachment[]\n reactions?: IMessageReaction\n location ?: IMessageLocation\n u?: IUser // User that sent the message\n editedBy?: IUser // User that edited the message\n editedAt?: Date // When the message was edited\n}\n\nexport interface IUser {\n _id: string\n username: string\n name?: string\n}\n\nexport interface IMessageAttachment {\n fields?: IAttachmentField[]\n actions?: IMessageAction[]\n color?: string\n text?: string\n ts?: string\n thumb_url?: string\n message_link?: string\n collapsed?: boolean\n author_name?: string\n author_link?: string\n author_icon?: string\n title?: string\n title_link?: string\n title_link_download?: string\n image_url?: string\n audio_url?: string\n video_url?: string\n}\n\nexport interface IAttachmentField {\n short?: boolean\n title?: string\n value?: string\n}\n\nexport interface IMessageAction {\n type?: string,\n text?: string,\n url?: string,\n image_url?: string,\n is_webview?: boolean,\n webview_height_ratio?: string,\n msg?: string,\n msg_in_chat_window?: boolean\n}\n\nexport interface IMessageLocation {\n type: string // e.g. Point\n coordinates: string[] // longitude latitude\n}\n\nexport interface IMessageReaction {\n [emoji: string]: { usernames: string[] } // emoji: [usernames that reacted]\n}\n"]}
\ No newline at end of file
......@@ -339,7 +339,7 @@ function respondToMessages(callback, options = {}) {
config.rooms.length > 0) {
promise = joinRooms(config.rooms)
.catch((err) => {
log_1.logger.error(`Failed to join rooms set in env: ${config.rooms}`, err);
log_1.logger.error(`[joinRooms] Failed to join configured rooms (${config.rooms.join(', ')}): ${err.message}`);
});
}
exports.lastReadTime = new Date(); // init before any message read
......@@ -410,7 +410,7 @@ function joinRoom(room) {
let roomId = yield getRoomId(room);
let joinedIndex = exports.joinedIds.indexOf(room);
if (joinedIndex !== -1) {
log_1.logger.error(`tried to join room that was already joined`);
log_1.logger.error(`[joinRoom] room was already joined`);
}
else {
yield asyncCall('joinRoom', roomId);
......@@ -425,7 +425,7 @@ function leaveRoom(room) {
let roomId = yield getRoomId(room);
let joinedIndex = exports.joinedIds.indexOf(room);
if (joinedIndex === -1) {
log_1.logger.error(`leave room ${room} failed because bot has not joined in room`);
log_1.logger.error(`[leaveRoom] failed because bot has not joined ${room}`);
}
else {
yield asyncCall('leaveRoom', roomId);
......
This diff is collapsed.
/** @todo contribute these to @types/rocketchat and require */
export interface IMessage {
rid: string | null // room ID
_id?: string // generated by Random.id()
t?: string // type e.g. rm
msg?: string // text content
alias?: string // ??
emoji?: string // emoji to use as avatar
avatar?: string // url
groupable?: boolean // ?
bot?: any // integration details
urls?: string[] // ?
mentions?: string[] // ?
reactions?: { [emoji: string]: { usernames: string[] } } // emoji: [usernames]
location?: {
type: string // e.g. Point
coordinates: string[] // longitude latitude
}
attachments?: IAttachment[]
editedAt?: Date
editedBy?: {
_id: string
username: string
}
u?: { // the user who sent the message
_id: string
username: string
name: string
}
rid: string | null // room ID
_id?: string // generated by Random.id()
t?: string // type e.g. rm
msg?: string // text content
alias?: string // ??
emoji?: string // emoji to use as avatar
avatar?: string // url
groupable?: boolean // ?
bot?: any // integration details
urls?: string[] // ?
mentions?: string[] // ?
attachments?: IMessageAttachment[]
reactions?: IMessageReaction
location ?: IMessageLocation
u?: IUser // User that sent the message
editedBy?: IUser // User that edited the message
editedAt?: Date // When the message was edited
}
export interface IAttachment {
export interface IUser {
_id: string
username: string
name?: string
}
export interface IMessageAttachment {
fields?: IAttachmentField[]
actions?: IMessageAction[]
color?: string
text?: string
ts?: string
......@@ -54,3 +51,23 @@ export interface IAttachmentField {
title?: string
value?: string
}
export interface IMessageAction {
type?: string,
text?: string,
url?: string,
image_url?: string,
is_webview?: boolean,
webview_height_ratio?: string,
msg?: string,
msg_in_chat_window?: boolean
}
export interface IMessageLocation {
type: string // e.g. Point
coordinates: string[] // longitude latitude
}
export interface IMessageReaction {
[emoji: string]: { usernames: string[] } // emoji: [usernames that reacted]
}
......@@ -164,18 +164,33 @@ describe('driver', () => {
})
it('sends a custom message', async () => {
const message = driver.prepareMessage({
rid: tId,
msg: ':point_down:',
emoji: ':point_right:',
reactions: { ':thumbsup:': { usernames: [botUser.username] } },
groupable: false,
rid: tId
groupable: false
})
const result = await driver.sendMessage(message)
await driver.sendMessage(message)
const last = (await utils.lastMessages(tId))[0]
expect(last).to.have.deep.property('reactions', message.reactions)
expect(last).to.have.property('emoji', ':point_right:')
expect(last).to.have.property('msg', ':point_down:')
})
it('sends a message with actions', async () => {
const attachments = [{
actions: [
{ type: 'button', text: 'Action 1', msg: 'Testing Action 1', msg_in_chat_window: true },
{ type: 'button', text: 'Action 2', msg: 'Testing Action 2', msg_in_chat_window: true }
]
}]
await driver.sendMessage({
rid: tId,
msg: 'SDK test `prepareMessage` actions',
attachments
})
const last = (await utils.lastMessages(tId))[0]
expect(last.attachments).to.eql(attachments)
})
})
describe('.editMessage', () => {
before(async () => {
......
......@@ -377,7 +377,7 @@ export function respondToMessages (
) {
promise = joinRooms(config.rooms)
.catch((err) => {
logger.error(`Failed to join rooms set in env: ${config.rooms}`, err)
logger.error(`[joinRooms] Failed to join configured rooms (${config.rooms.join(', ')}): ${err.message}`)
})
}
......@@ -452,7 +452,7 @@ export async function joinRoom (room: string): Promise<void> {
let roomId = await getRoomId(room)
let joinedIndex = joinedIds.indexOf(room)
if (joinedIndex !== -1) {
logger.error(`tried to join room that was already joined`)
logger.error(`[joinRoom] room was already joined`)
} else {
await asyncCall('joinRoom', roomId)
joinedIds.push(roomId)
......@@ -464,7 +464,7 @@ export async function leaveRoom (room: string): Promise<void> {
let roomId = await getRoomId(room)
let joinedIndex = joinedIds.indexOf(room)
if (joinedIndex === -1) {
logger.error(`leave room ${room} failed because bot has not joined in room`)
logger.error(`[leaveRoom] failed because bot has not joined ${room}`)
} else {
await asyncCall('leaveRoom', roomId)
delete joinedIds[joinedIndex]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment