appsocom 0.5.0__tar.gz → 0.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {appsocom-0.5.0 → appsocom-0.6.3}/PKG-INFO +1 -1
- {appsocom-0.5.0 → appsocom-0.6.3}/appsocom/__init__.py +88 -1
- {appsocom-0.5.0 → appsocom-0.6.3}/appsocom.egg-info/PKG-INFO +1 -1
- {appsocom-0.5.0 → appsocom-0.6.3}/pyproject.toml +1 -1
- {appsocom-0.5.0 → appsocom-0.6.3}/tests/test_sfukit.py +30 -0
- {appsocom-0.5.0 → appsocom-0.6.3}/LICENSE +0 -0
- {appsocom-0.5.0 → appsocom-0.6.3}/README.md +0 -0
- {appsocom-0.5.0 → appsocom-0.6.3}/appsocom.egg-info/SOURCES.txt +0 -0
- {appsocom-0.5.0 → appsocom-0.6.3}/appsocom.egg-info/dependency_links.txt +0 -0
- {appsocom-0.5.0 → appsocom-0.6.3}/appsocom.egg-info/top_level.txt +0 -0
- {appsocom-0.5.0 → appsocom-0.6.3}/setup.cfg +0 -0
|
@@ -19,7 +19,7 @@ import urllib.request
|
|
|
19
19
|
from typing import Any, Dict, List, Optional, Sequence, Union
|
|
20
20
|
|
|
21
21
|
__all__ = ["SfuKit", "SfuKitError", "sign_token", "verify_webhook", "sign_webhook", "SIGNATURE_HEADER"]
|
|
22
|
-
__version__ = "0.
|
|
22
|
+
__version__ = "0.6.3"
|
|
23
23
|
|
|
24
24
|
SIGNATURE_HEADER = "X-SfuKit-Signature"
|
|
25
25
|
_ID = re.compile(r"^[A-Za-z0-9._:@-]{1,128}$")
|
|
@@ -253,6 +253,93 @@ class SfuKit:
|
|
|
253
253
|
"""A finished lesson's report: summary, per-learner results and feedback, alerts, transcript."""
|
|
254
254
|
return self.request("GET", f"/lessons/{_id(lesson_id)}/report")
|
|
255
255
|
|
|
256
|
+
# ---------- AI Presenter (product demos and walkthroughs) ----------
|
|
257
|
+
|
|
258
|
+
def start_presenter(self, room_id: str, **options: Any) -> Dict[str, Any]:
|
|
259
|
+
"""Start an AI Presenter from an approved presentation kit. options: planId (or lesson), lead ("ai"|"human"),
|
|
260
|
+
name, voice, avatar, reportEmails, webhookUrl, maxMinutes. Returns {"presentationId", "lessonId", "agentId", ...}.
|
|
261
|
+
Stop it with stop_lesson."""
|
|
262
|
+
return self.request("POST", f"/rooms/{_id(room_id)}/presenter", options)
|
|
263
|
+
|
|
264
|
+
def set_presenter_lead(self, room_id: str, presentation_id: str, lead: str) -> None:
|
|
265
|
+
"""lead: "ai" or "human"."""
|
|
266
|
+
self.control_lesson(room_id, presentation_id, "lead", lead=lead)
|
|
267
|
+
|
|
268
|
+
def presenter_browser(self, room_id: str, presentation_id: str, action: Union[str, Dict[str, Any]]) -> None:
|
|
269
|
+
"""The live demo's cloud browser: "take", "give", "close", or an op such as
|
|
270
|
+
{"op": "click-at", "x": 0.4, "y": 0.2} or {"op": "scroll", "direction": "down"}."""
|
|
271
|
+
if isinstance(action, dict):
|
|
272
|
+
self.control_lesson(room_id, presentation_id, "browser", browser="op", op=action)
|
|
273
|
+
else:
|
|
274
|
+
self.control_lesson(room_id, presentation_id, "browser", browser=action)
|
|
275
|
+
|
|
276
|
+
def upload_presentation_assets(self, files: Sequence[tuple]) -> Dict[str, Any]:
|
|
277
|
+
"""files: [(filename, bytes), ...] screenshots (PNG, JPEG, WebP, GIF; up to 5 MB each, 20 at once).
|
|
278
|
+
Returns {"assets": [{"name", "url"}]}: use the links as screen imageUrl in the kit."""
|
|
279
|
+
types = {"png": "image/png", "jpg": "image/jpeg", "jpeg": "image/jpeg", "webp": "image/webp", "gif": "image/gif"}
|
|
280
|
+
boundary = "sfukit" + hashlib.sha256(str(time.time()).encode()).hexdigest()[:24]
|
|
281
|
+
parts: List[bytes] = []
|
|
282
|
+
for name, data in files:
|
|
283
|
+
safe = str(name).replace('"', "").replace("\r", "").replace("\n", "")
|
|
284
|
+
ctype = types.get(safe.rsplit(".", 1)[-1].lower(), "application/octet-stream")
|
|
285
|
+
parts.append(f'--{boundary}\r\nContent-Disposition: form-data; name="file"; filename="{safe}"\r\nContent-Type: {ctype}\r\n\r\n'.encode("utf-8") + bytes(data) + b"\r\n")
|
|
286
|
+
parts.append(f"--{boundary}--\r\n".encode("utf-8"))
|
|
287
|
+
return self.request("POST", "/presentation-assets", _encoded=(b"".join(parts), f"multipart/form-data; boundary={boundary}"))
|
|
288
|
+
|
|
289
|
+
def list_presentation_reports(self, plan_id: Optional[str] = None) -> Dict[str, Any]:
|
|
290
|
+
"""Presentations that ended, newest first (optionally of one kit): {"presentations": [...]}."""
|
|
291
|
+
q = f"?planId={urllib.parse.quote(plan_id, safe='')}" if plan_id is not None else ""
|
|
292
|
+
return self.request("GET", f"/presentation-reports{q}")
|
|
293
|
+
|
|
294
|
+
def get_presentation_report(self, report_id: str) -> Dict[str, Any]:
|
|
295
|
+
"""One presentation: summary, recommendations, questions and suggestions."""
|
|
296
|
+
return self.request("GET", f"/presentation-reports/{_id(report_id)}")
|
|
297
|
+
|
|
298
|
+
def review_suggestion(self, report_id: str, index: int, status: str) -> Dict[str, Any]:
|
|
299
|
+
"""status: "new", "reviewed", "accepted" or "dismissed"."""
|
|
300
|
+
return self.request("PUT", f"/presentation-reports/{_id(report_id)}/suggestions/{int(index)}", {"status": status})
|
|
301
|
+
|
|
302
|
+
# ---- self-running presentations: a link the AI Presenter presents on its own, privately to each visitor
|
|
303
|
+
|
|
304
|
+
def create_presentation_link(self, plan_id: str, **options: Any) -> Dict[str, Any]:
|
|
305
|
+
"""A link from an approved kit. options: title, name, voice, avatar, reportEmails, askDetails,
|
|
306
|
+
maxMinutes (30), perDay (50), maxConcurrent (5), active."""
|
|
307
|
+
return self.request("POST", "/presentation-links", {"planId": plan_id, **options})
|
|
308
|
+
|
|
309
|
+
def list_presentation_links(self) -> Dict[str, Any]:
|
|
310
|
+
return self.request("GET", "/presentation-links")
|
|
311
|
+
|
|
312
|
+
def get_presentation_link(self, link_id: str) -> Dict[str, Any]:
|
|
313
|
+
return self.request("GET", f"/presentation-links/{_id(link_id)}")
|
|
314
|
+
|
|
315
|
+
def update_presentation_link(self, link_id: str, **patch: Any) -> Dict[str, Any]:
|
|
316
|
+
"""Fields you leave out stay; active=False closes the link."""
|
|
317
|
+
return self.request("PATCH", f"/presentation-links/{_id(link_id)}", patch)
|
|
318
|
+
|
|
319
|
+
def delete_presentation_link(self, link_id: str) -> None:
|
|
320
|
+
self.request("DELETE", f"/presentation-links/{_id(link_id)}")
|
|
321
|
+
|
|
322
|
+
def start_presentation_session(self, link_id: str, name: Optional[str] = None, email: Optional[str] = None, company: Optional[str] = None, phone: Optional[str] = None) -> Dict[str, Any]:
|
|
323
|
+
"""A visitor opened the link. Returns {"sessionId", "roomId", "token", "expiresAt"}; the presenter
|
|
324
|
+
starts when they join. Past the link's limits the API answers 429."""
|
|
325
|
+
visitor = {k: v for k, v in {"name": name, "email": email, "company": company, "phone": phone}.items() if v}
|
|
326
|
+
return self.request("POST", f"/presentation-links/{_id(link_id)}/sessions", {"visitor": visitor})
|
|
327
|
+
|
|
328
|
+
def list_presentation_sessions(self, link_id: Optional[str] = None) -> Dict[str, Any]:
|
|
329
|
+
"""Visitors and their leads, newest first: {"sessions": [...]}."""
|
|
330
|
+
q = f"?linkId={urllib.parse.quote(link_id, safe='')}" if link_id else ""
|
|
331
|
+
return self.request("GET", f"/presentation-sessions{q}")
|
|
332
|
+
|
|
333
|
+
def get_presentation_session(self, session_id: str) -> Dict[str, Any]:
|
|
334
|
+
return self.request("GET", f"/presentation-sessions/{_id(session_id)}")
|
|
335
|
+
|
|
336
|
+
def join_presentation_session(self, session_id: str, name: str, user_id: Optional[str] = None) -> Dict[str, Any]:
|
|
337
|
+
"""A host token for a colleague to step into a visitor's presentation."""
|
|
338
|
+
body: Dict[str, Any] = {"name": name}
|
|
339
|
+
if user_id:
|
|
340
|
+
body["userId"] = user_id
|
|
341
|
+
return self.request("POST", f"/presentation-sessions/{_id(session_id)}/join", body)
|
|
342
|
+
|
|
256
343
|
def learner_progress(self, learner_id: str) -> Dict[str, Any]:
|
|
257
344
|
return self.request("GET", f"/learners/{urllib.parse.quote(learner_id, safe='')}/progress")
|
|
258
345
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "appsocom"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.6.3"
|
|
8
8
|
description = "Python server SDK for Appsocom Live video calls: join tokens, rooms, moderation and webhook verification"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -113,6 +113,36 @@ class AdminTests(unittest.TestCase):
|
|
|
113
113
|
kit.update_room("r1", waiting_room=True)
|
|
114
114
|
self.assertEqual(Handler.seen[-1][3], {"waitingRoom": True})
|
|
115
115
|
|
|
116
|
+
def test_presenter(self):
|
|
117
|
+
kit = self.kit
|
|
118
|
+
kit.start_presenter("demo", planId="p1", lead="human")
|
|
119
|
+
self.assertEqual(Handler.seen[-1], ("POST", "/rooms/demo/presenter", "Bearer k", {"planId": "p1", "lead": "human"}))
|
|
120
|
+
kit.presenter_browser("demo", "agent-1", "take")
|
|
121
|
+
self.assertEqual(Handler.seen[-1][1:], ("/rooms/demo/lessons/agent-1/control", "Bearer k", {"action": "browser", "browser": "take"}))
|
|
122
|
+
kit.presenter_browser("demo", "agent-1", {"op": "click-at", "x": 0.5, "y": 0.25})
|
|
123
|
+
self.assertEqual(Handler.seen[-1][3], {"action": "browser", "browser": "op", "op": {"op": "click-at", "x": 0.5, "y": 0.25}})
|
|
124
|
+
kit.set_presenter_lead("demo", "agent-1", "ai")
|
|
125
|
+
self.assertEqual(Handler.seen[-1][3], {"action": "lead", "lead": "ai"})
|
|
126
|
+
kit.list_presentation_reports("p 1")
|
|
127
|
+
self.assertEqual(Handler.seen[-1][1], "/presentation-reports?planId=p%201")
|
|
128
|
+
kit.review_suggestion("agent-1", 2, "accepted")
|
|
129
|
+
self.assertEqual(Handler.seen[-1], ("PUT", "/presentation-reports/agent-1/suggestions/2", "Bearer k", {"status": "accepted"}))
|
|
130
|
+
|
|
131
|
+
def test_self_running_presentations(self):
|
|
132
|
+
kit = self.kit
|
|
133
|
+
kit.create_presentation_link("p1", title="Proposal", maxConcurrent=2)
|
|
134
|
+
self.assertEqual(Handler.seen[-1], ("POST", "/presentation-links", "Bearer k", {"planId": "p1", "title": "Proposal", "maxConcurrent": 2}))
|
|
135
|
+
kit.update_presentation_link("pl_1", active=False)
|
|
136
|
+
self.assertEqual(Handler.seen[-1], ("PATCH", "/presentation-links/pl_1", "Bearer k", {"active": False}))
|
|
137
|
+
kit.start_presentation_session("pl_1", name="Ngozi", email="n@x.ng")
|
|
138
|
+
self.assertEqual(Handler.seen[-1], ("POST", "/presentation-links/pl_1/sessions", "Bearer k", {"visitor": {"name": "Ngozi", "email": "n@x.ng"}}))
|
|
139
|
+
kit.list_presentation_sessions("pl 1")
|
|
140
|
+
self.assertEqual(Handler.seen[-1][1], "/presentation-sessions?linkId=pl%201")
|
|
141
|
+
kit.join_presentation_session("ps_1", "Tunde")
|
|
142
|
+
self.assertEqual(Handler.seen[-1][1:], ("/presentation-sessions/ps_1/join", "Bearer k", {"name": "Tunde"}))
|
|
143
|
+
kit.delete_presentation_link("pl_1")
|
|
144
|
+
self.assertEqual(Handler.seen[-1][:2], ("DELETE", "/presentation-links/pl_1"))
|
|
145
|
+
|
|
116
146
|
def test_errors(self):
|
|
117
147
|
with self.assertRaises(SfuKitError) as e:
|
|
118
148
|
self.kit.get_room("missing")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|