feat(Microsoft Teams Node): Add chat message support (#2635)

*  Add chat messages to MS Teams node

* Updated credentials to include missing scope

*  Small improvements

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
pemontto
2022-04-01 16:21:25 +01:00
committed by GitHub
parent 39a6f41720
commit 984f62df9e
3 changed files with 269 additions and 1 deletions

View File

@@ -26,6 +26,11 @@ import {
channelMessageOperations,
} from './ChannelMessageDescription';
import {
chatMessageFields,
chatMessageOperations,
} from './ChatMessageDescription';
import {
taskFields,
taskOperations,
@@ -65,6 +70,10 @@ export class MicrosoftTeams implements INodeType {
name: 'Channel Message (Beta)',
value: 'channelMessage',
},
{
name: 'Chat Message',
value: 'chatMessage',
},
{
name: 'Task',
value: 'task',
@@ -79,6 +88,8 @@ export class MicrosoftTeams implements INodeType {
/// MESSAGE
...channelMessageOperations,
...channelMessageFields,
...chatMessageOperations,
...chatMessageFields,
///TASK
...taskOperations,
...taskFields,
@@ -189,6 +200,29 @@ export class MicrosoftTeams implements INodeType {
}
return returnData;
},
// Get all the chats to display them to user so that they can
// select them easily
async getChats(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {
$expand: 'members',
};
const { value } = await microsoftApiRequest.call(this, 'GET', '/v1.0/chats', {}, qs);
for (const chat of value) {
if (!chat.topic) {
chat.topic = chat.members
.filter((member: IDataObject) => member.displayName)
.map((member: IDataObject) => member.displayName).join(', ');
}
const chatName = `${chat.topic || '(no title) - ' + chat.id} (${chat.chatType})`;
const chatId = chat.id;
returnData.push({
name: chatName,
value: chatId,
});
}
return returnData;
},
},
};
@@ -298,6 +332,39 @@ export class MicrosoftTeams implements INodeType {
}
}
}
if (resource === 'chatMessage') {
// https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http
if (operation === 'create') {
const chatId = this.getNodeParameter('chatId', i) as string;
const messageType = this.getNodeParameter('messageType', i) as string;
const message = this.getNodeParameter('message', i) as string;
const body: IDataObject = {
body: {
contentType: messageType,
content: message,
},
};
responseData = await microsoftApiRequest.call(this, 'POST', `/v1.0/chats/${chatId}/messages`, body);
}
// https://docs.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
if (operation === 'get') {
const chatId = this.getNodeParameter('chatId', i) as string;
const messageId = this.getNodeParameter('messageId', i) as string;
responseData = await microsoftApiRequest.call(this, 'GET', `/v1.0/chats/${chatId}/messages/${messageId}`);
}
// https://docs.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
if (operation === 'getAll') {
const chatId = this.getNodeParameter('chatId', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll) {
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/chats/${chatId}/messages`);
} else {
qs.limit = this.getNodeParameter('limit', i) as number;
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/v1.0/chats/${chatId}/messages`, {});
responseData = responseData.splice(0, qs.limit);
}
}
}
if (resource === 'task') {
//https://docs.microsoft.com/en-us/graph/api/planner-post-tasks?view=graph-rest-1.0&tabs=http
if (operation === 'create') {