-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathsimple.py
More file actions
executable file
·91 lines (67 loc) · 3.06 KB
/
Copy pathsimple.py
File metadata and controls
executable file
·91 lines (67 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple webexpythonsdk demonstration script.
Very simple script to create a demo room, post a message, and post a file.
If one or more rooms with the name of the demo room already exist, it will
delete the previously existing rooms.
The package natively retrieves your Webex access token from the
WEBEX_ACCESS_TOKEN environment variable. You must have this environment
variable set to run this script.
Copyright (c) 2016-2024 Cisco and/or its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from webexpythonsdk import WebexAPI
DEMO_ROOM_NAME = "webexpythonsdk Demo Room"
DEMO_PEOPLE = ["test01@cmlccie.com", "test02@cmlccie.com"]
DEMO_MESSAGE = "Webex rocks! \ud83d\ude0e"
DEMO_FILE_URL = (
"https://www.webex.com/content/dam/wbx/us/images/dg-integ/teams_icon.png"
)
# Create a WebexAPI connection object; uses your WEBEX_ACCESS_TOKEN
api = WebexAPI()
# Clean up previous demo rooms
print("Searching for existing demo rooms...")
# Create a generator container (iterable) that lists the rooms where you are
# a member
rooms = api.rooms.list()
# Build a list of rooms with the name DEMO_ROOM_NAME
existing_demo_rooms = [room for room in rooms if room.title == DEMO_ROOM_NAME]
if existing_demo_rooms:
print(
"Found {} existing room(s); deleting them." "".format(
len(existing_demo_rooms)
)
)
for room in existing_demo_rooms:
# Delete the room
api.rooms.delete(room.id)
print("Room '{}' deleted.".format(room.id))
# Create a new demo room
demo_room = api.rooms.create(DEMO_ROOM_NAME)
# Print the room details (formatted JSON)
print(demo_room)
for person_email in DEMO_PEOPLE:
# Add people to the room
api.memberships.create(demo_room.id, personEmail=person_email)
# Create a message in the new room
message = api.messages.create(demo_room.id, text=DEMO_MESSAGE)
# Print the message details (formatted JSON)
print(message)
# Post a file in the new room from test_url
message = api.messages.create(demo_room.id, files=[DEMO_FILE_URL])
# Print the message details (formatted JSON)
print(message)