Thank you brbester for the enhancement request and sharing your code on how you had solved this previously!
When creating a new message, the `files` argument now accepts either a valid HTTP/HTTPS Internet URL or a path to a local file that should be uploaded when the message is created.
Note that the `files` argument only accepts a **_list_ containing a single item** (a string containing either a URL or a local file path). This is a Spark API limitation that may be lifted at a future date. We have implemented method consistent with the Spark API to provide for backwards compatibility if/when this enhancement is made in the future. This way, when Spark opens up support for attaching multiple files on a single message (and we update the package to support that capability), we will not change the method's API and break calls to this method from existing code leveraging the package.
Example of the new functionality:
python
from ciscosparkapi import CiscoSparkAPI
api = CiscoSparkAPI()
DEMO_ROOM_NAME = "ciscosparkapi Test Room"
DEMO_PEOPLE = ["test01cmlccie.com", "test02cmlccie.com"]
DEMO_TEXT = u"Cisco Spark rocks! \ud83d\ude0e"
DEMO_FILE_URL = "https://developer.ciscospark.com/images/logo_spark_lg256.png"
MARKDOWN_TEXT = "**This was uploaded from a local file!**"
DEMO_LOCAL_FILE = "picture.jpg"
Create a new test room
demo_room = api.rooms.create(DEMO_ROOM_NAME)
Add people to the room
for person_email in DEMO_PEOPLE:
api.memberships.create(test_room.id, personEmail=person_email)
Post a plain-text message to the room, with an attachment from an Internet URL
message1 = api.messages.create(test_room.id, text=DEMO_TEXT, files=[DEMO_FILE_URL])
print(message1)
Post a markdown-message to the room, with an attachment uploaded from a local file
message2 = api.messages.create(test_room.id, markdown=MARKDOWN_TEXT, files=[DEMO_LOCAL_FILE])
print(message2)