Skip to content

Commit

Permalink
[PLGN-391] - Microsoft Teams -adding in new actions for getting messa…
Browse files Browse the repository at this point in the history
…ges from a chat and creating a chat (#2106)

* PLG-391-adding in new actions for getting messages from a chat and creating a chat

* PLG-391-adding in new actions for getting messages from a chat and creating a chat

* PLG-391-updating return types to corretc types, better handling of errors in list_messages_from_chat

* PLGN-391-Adding in schema validation to unit tests

* PLGN-391-Bumping validators from 0.17.0 to 0.21.0

* PLGN-391-Adding better error handling for non json response, fixing type of members

* PLGN-391-black formatter
  • Loading branch information
rbowden-r7 committed Nov 16, 2023
1 parent b30d584 commit 77d7294
Show file tree
Hide file tree
Showing 38 changed files with 1,212 additions and 45 deletions.
20 changes: 14 additions & 6 deletions plugins/microsoft_teams/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec": "c789730bf7c262c32f372f8e86753df8",
"manifest": "8a7b4cfc9567a23d50706d49807dc753",
"setup": "a75c05ebbf3c01d5d5da5687a9bd0036",
"spec": "c9becfea96f7b49ec9f3f739d57a402d",
"manifest": "cf57f82d2fd650136689da39f1359bba",
"setup": "07ef2d2945cdd65380bb0e3d8e4d3a4f",
"schemas": [
{
"identifier": "add_channel_to_team/schema.py",
Expand All @@ -19,6 +19,10 @@
"identifier": "add_member_to_team/schema.py",
"hash": "daf644fdedf69570b4de8d3c8b5d4692"
},
{
"identifier": "create_teams_chat/schema.py",
"hash": "624f57b6ee026fa69e74e6ba2ebf732b"
},
{
"identifier": "create_teams_enabled_group/schema.py",
"hash": "9d1a41cc30c7af5e5c61841b586f0a3b"
Expand All @@ -33,20 +37,24 @@
},
{
"identifier": "get_message_in_channel/schema.py",
"hash": "435e1e4e395f4bb806768e88c09ab444"
"hash": "b8b1956f659ff8070bf11ac27f20e1dc"
},
{
"identifier": "get_message_in_chat/schema.py",
"hash": "bfa7d0852b744793ab8ba7e935263629"
"hash": "7084e6609fae0c1da35859d3507cf0e2"
},
{
"identifier": "get_reply_list/schema.py",
"hash": "ae7a21cb4211617fe55bf557192e6841"
"hash": "d299f50370d5d1672687faf0defa92be"
},
{
"identifier": "get_teams/schema.py",
"hash": "d4167388ba5726a8f13639844294cee5"
},
{
"identifier": "list_messages_in_chat/schema.py",
"hash": "b20a85b662826aabdd19c0fa6c55aecc"
},
{
"identifier": "remove_channel_from_team/schema.py",
"hash": "02305968869d8a40c21c7e2176862ddc"
Expand Down
6 changes: 5 additions & 1 deletion plugins/microsoft_teams/bin/icon_microsoft_teams
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from sys import argv

Name = "Microsoft Teams"
Vendor = "rapid7"
Version = "5.1.0"
Version = "6.0.0"
Description = "The Microsoft Teams plugin allows you to send and trigger workflows on new messages. The plugin will also allow for teams management with the ability to add and remove teams, channels, and users"


Expand Down Expand Up @@ -68,6 +68,10 @@ def main():

self.add_action(actions.GetReplyList())

self.add_action(actions.ListMessagesInChat())

self.add_action(actions.CreateTeamsChat())


"""Run plugin"""
cli = insightconnect_plugin_runtime.CLI(ICONMicrosoftTeams())
Expand Down
134 changes: 133 additions & 1 deletion plugins/microsoft_teams/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,61 @@ Example output:
}
```

#### Create Teams Chat

Create a chat in Microsoft Teams

##### Input

|Name|Type|Default|Required|Description|Enum|Example|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|members|[]itemMember|None|True|A list of usernames to set as members|None|[{"user_info": "user@example.com", "role": "owner"}, {"user_info": "ab123bcd-123a-412a3-abc1-a123456b789c", "role": "owner"}]|
|topic|string|None|False|Topic of chat to be added (only available for group chats)|None|example_topic|

Example input:

```
{
"members": [
{
"Role": "owner",
"User Info": "user@example.com"
},
{
"Role": "owner",
"User Info": "ab123bcd-123a-412a3-abc1-a123456b789c"
},
{
"Role": "owner",
"User Info": "cb123bcd-123a-412a3-abc1-a123456b789c"
}
],
"topic": "example_topic"
}
```

##### Output

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|chat|itemChat|False|Information about the chat that was created|{'@odata.context': 'https://graph.microsoft.com/beta/$metadata#chats/$entity', 'chatType': 'group', 'createdDateTime': '2023-11-09T12:07:43.167Z', 'id': '12:a12345bc678d901e12345f67890g1234_thread.v2', 'lastUpdatedDateTime': '2023-11-09T12:07:43.167Z', 'tenantId': '1a234567-bc8d-9e01-23fg-4h567i8j9k01', 'webUrl': 'https://teams.microsoft.com/l/chat/12%3AA12345BC678D901E12345F67890G1234%40thread.v2/0tenantId=1a234567-bc8d-9e01-23fg-4h567i8j9k01'}|

Example output:

```
{
"chat": {
"@odata.context": "https://graph.microsoft.com/beta/$metadata#chats/$entity",
"chatType": "group",
"createdDateTime": "2023-11-09T12:07:43.167Z",
"id": "12:a12345bc678d901e12345f67890g1234_thread.v2",
"lastUpdatedDateTime": "2023-11-09T12:07:43.167Z",
"tenantId": "1a234567-bc8d-9e01-23fg-4h567i8j9k01",
"webUrl": "https://teams.microsoft.com/l/chat/12%3AA12345BC678D901E12345F67890G1234%40thread.v2/0tenantId=1a234567-bc8d-9e01-23fg-4h567i8j9k01"
}
}
```

#### Create Teams Enabled Group

Create a group in Azure and enable it for Microsoft Teams
Expand Down Expand Up @@ -543,6 +598,63 @@ Example output:
}
```

#### List Messages from a Chat

Retrieve up to the last 50 messages in a chat

##### Input

|Name|Type|Default|Required|Description|Enum|Example|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|chat_id|string|None|True|The ID of chat|None|11:examplechat.name|

Example input:

```
{
"chat_id": "11:examplechat.name"
}
```

##### Output

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|messages|[]chatMessage|False|The message object that was created|[{"attachments": [], "body": {"content": "Test message", "contentType": "text"}, "chatId": "12:a12345bc678d901e12345f67890g1234_thread.v2", "createdDateTime": "2023-11-08T10:38:18.048Z", "etag": "1234567890123", "from": {"user": {"@odata.type": "#microsoft.graph.teamworkUserIdentity", "displayName": "Test User", "id": "8a234567-bc8d-9e01-23fg-4h567i8j9k98", "tenantId": "1a234567-bc8d-9e01-23fg-4h567i8j9k01", "userIdentityType": "aadUser"}}, "id": "1234567890123", "importance": "normal", "lastModifiedDateTime": "2023-11-08T10:38:18.048Z", "locale": "en-us", "mentions": [], "messageType": "message", "reactions": []}]|

Example output:

```
{
"messages": {
"attachments": [],
"body": {
"content": "Test message",
"contentType": "text"
},
"chatId": "12:a12345bc678d901e12345f67890g1234_thread.v2",
"createdDateTime": "2023-11-08T10:38:18.048Z",
"etag": "1234567890123",
"from": {
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"displayName": "Test User",
"id": "8a234567-bc8d-9e01-23fg-4h567i8j9k98",
"tenantId": "1a234567-bc8d-9e01-23fg-4h567i8j9k01",
"userIdentityType": "aadUser"
}
},
"id": "1234567890123",
"importance": "normal",
"lastModifiedDateTime": "2023-11-08T10:38:18.048Z",
"locale": "en-us",
"mentions": [],
"messageType": "message",
"reactions": []
}
}
```

#### Remove Channel from Team

Remove a channel from a team
Expand Down Expand Up @@ -1004,7 +1116,7 @@ Example output:
|Created Date Time|string|None|False|Created date time|None|
|Deleted Date Time|string|None|False|Deleted date time|None|
|Etag|string|None|False|Version number of the chat message|None|
|Event Detail|string|None|False|Represents details of an event that happened in a chat|None|
|Event Detail|object|None|False|Represents details of an event that happened in a chat|None|
|From|from|None|False|Details of the sender of the chat message|None|
|ID|string|None|False|Unique ID of the message|None|
|Importance|string|None|False|The importance of the chat message|None|
Expand All @@ -1020,6 +1132,25 @@ Example output:
|Subject|string|None|False|The subject of the chat message, in plaintext|None|
|Summary|string|None|False|Summary text of the chat message that could be used for push notifications and summary views or fall back views|None|
|Web URL|string|None|False|Link to the message in Microsoft Teams|None|

**itemMember**

|Name|Type|Default|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- | :--- |
|Role|string|None|True|The role of the user to be added to the chat|None|
|User Info|string|None|True|The ID or Email address|None|

**itemChat**

|Name|Type|Default|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- | :--- |
|Data Context|string|None|False|The context of the newly created chat|None|
|Chat Type|string|None|False|The type of the newly created chat|None|
|Created Date Time|string|None|False|Created date time|None|
|Chat ID|string|None|False|The ID of the newly created chat|None|
|Last Updated Date Time|string|None|False|Last updated date time|None|
|Tenant ID|string|None|False|The ID the directory that he newly created chat is in|None|
|Web URL|string|None|False|The URL of the newly created chat|None|


## Troubleshooting
Expand All @@ -1028,6 +1159,7 @@ If there is more than one team with the same name in your organization, the olde

# Version History

* 6.0.0 - New actions: `create_teams_chat` | `list_messages_in_chat` | update type of `Event Detail` to type object
* 5.1.0 - New actions: Get Reply List | Improve typing on message
* 5.0.0 - New actions: Get Message in Chat, Get Message in Channel | Update to latest SDK version | Change required fields in message schema
* 4.2.0 - New Message Received: Fixed issue where `font-size` value appeared in the `urls`, and `domains` output fields | Can choose the role of a member when adding them to a channel | Fix bug where case-sensitive URLs were returned in lower case | Improved reliability of domains output value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@
from .get_message_in_chat.action import GetMessageInChat

from .get_reply_list.action import GetReplyList

from .list_messages_in_chat.action import ListMessagesInChat

from .create_teams_chat.action import CreateTeamsChat

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import CreateTeamsChat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import insightconnect_plugin_runtime
from .schema import CreateTeamsChatInput, CreateTeamsChatOutput, Input, Output, Component


# Custom imports below
from icon_microsoft_teams.util.komand_clean_with_nulls import remove_null_and_clean
from icon_microsoft_teams.util.teams_utils import create_chat


class CreateTeamsChat(insightconnect_plugin_runtime.Action):
def __init__(self):
super(self.__class__, self).__init__(
name="create_teams_chat",
description=Component.DESCRIPTION,
input=CreateTeamsChatInput(),
output=CreateTeamsChatOutput(),
)

def run(self, params={}):
members = params.get(Input.MEMBERS)
topic = params.get(Input.TOPIC)

group_result = create_chat(self.connection, members, topic)

return {Output.CHAT: remove_null_and_clean(group_result)}
Loading

0 comments on commit 77d7294

Please sign in to comment.