Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions tests/api/example_card.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Publish Adaptive Card schema"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"style": "Person",
"url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
"size": "Small"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"weight": "Bolder",
"text": "Matt Hidinger",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "None",
"text": "Created {{DATE(2017-02-14T06:08:39Z,SHORT)}}",
"isSubtle": true,
"wrap": true
}
],
"width": "stretch"
}
]
},
{
"type": "TextBlock",
"text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.",
"wrap": true
},
{
"type": "FactSet",
"facts": [
{
"title": "Board:",
"value": "Adaptive Card"
},
{
"title": "List:",
"value": "Backlog"
},
{
"title": "Assigned to:",
"value": "Matt Hidinger"
},
{
"title": "Due date:",
"value": "Not set"
}
]
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Set due date",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Date",
"id": "dueDate"
},
{
"type": "Input.Text",
"id": "comment",
"placeholder": "Add a comment",
"isMultiline": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "OK",
"url": "http://adaptivecards.io"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
29 changes: 26 additions & 3 deletions tests/api/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

import itertools

import json, pathlib
import pytest

import webexteamssdk
Expand Down Expand Up @@ -56,6 +56,25 @@ def direct_message_by_email(api, test_people):
api.messages.delete(message.id)


@pytest.fixture(scope="session")
def direct_message_by_email_with_card(api, test_people):
attachments = []
attachment = {}
attachment['contentType'] = "application/vnd.microsoft.card.adaptive"
attachment["content"] = json.loads(open(pathlib.Path(__file__).parent / 'example_card.json').read())
attachments.append(attachment)
person = test_people["member_added_by_email"]
message = api.messages.create(
toPersonEmail=person.emails[0],
text=create_string("Message"),
attachments=attachments
)

yield message

api.messages.delete(message.id)


@pytest.fixture(scope="session")
def direct_message_by_id(api, test_people):
person = test_people["member_added_by_id"]
Expand Down Expand Up @@ -137,8 +156,8 @@ def group_room_messages(api, group_room,


@pytest.fixture(scope="session")
def direct_messages(api, direct_message_by_email, direct_message_by_id):
return [direct_message_by_email, direct_message_by_id]
def direct_messages(api, direct_message_by_email, direct_message_by_id, direct_message_by_email_with_card):
return [direct_message_by_email, direct_message_by_id, direct_message_by_email_with_card]


# Tests
Expand Down Expand Up @@ -191,6 +210,10 @@ def test_create_direct_messages_by_email(direct_message_by_email):
assert is_valid_message(direct_message_by_email)


def test_create_direct_messages_by_email_with_card(direct_message_by_email_with_card):
assert is_valid_message(direct_message_by_email_with_card)


def test_create_direct_messages_by_id(direct_message_by_id):
assert is_valid_message(direct_message_by_id)

Expand Down
15 changes: 14 additions & 1 deletion webexteamssdk/api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def list(self, roomId, mentionedPeople=None, before=None,
yield self._object_factory(OBJECT_TYPE, item)

def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
text=None, markdown=None, files=None, **request_parameters):
text=None, markdown=None, files=None, attachments=None, **request_parameters):
"""Post a message, and optionally a attachment, to a room.

The files parameter is a list, which accepts multiple values to allow
Expand All @@ -154,6 +154,9 @@ def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
markdown(basestring): The message, in markdown format.
files(`list`): A list of public URL(s) or local path(s) to files to
be posted into the room. Only one file is allowed per message.
attachments(`list`): A list comprised of properly formatted button
and card data structure. This can be found at
https://docs.microsoft.com/en-us/adaptive-cards/sdk/designer
**request_parameters: Additional request parameters (provides
support for parameters that may be added in the future).

Expand All @@ -174,6 +177,7 @@ def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
check_type(text, basestring)
check_type(markdown, basestring)
check_type(files, list)
check_type(attachments, list)
if files:
if len(files) != 1:
raise ValueError("The length of the `files` list is greater "
Expand All @@ -184,6 +188,14 @@ def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
"message.")
check_type(files[0], basestring)

if attachments:
for attachment in attachments:
try:
content_type_exists = attachment['contentType']
except Exception as e:
# ensure a valid header is loaded for cards
attachment['contentType'] = 'application/vnd.microsoft.card.adaptive'

post_data = dict_from_items_with_values(
request_parameters,
roomId=roomId,
Expand All @@ -192,6 +204,7 @@ def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
text=text,
markdown=markdown,
files=files,
attachments=attachments,
)

# API request
Expand Down