Skip to content

Commit

Permalink
feat: add support for assistant-event directive (#12)
Browse files Browse the repository at this point in the history
* feat: add support for assistant-event directive

* feat: add unit test

Co-authored-by: Brady Lenz <[email protected]>
  • Loading branch information
bradylenz and bradylenz authored Jul 7, 2021
1 parent ebffc2d commit 41d52df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Implemented `new` CLI command
- Implemented `assistant-event` directive

### Changed

Expand Down
12 changes: 12 additions & 0 deletions tests/test_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ def test_long_reply(responder: SkillResponder, query: str, remove_hyphens: bool,
assert responder.directives[0]['type'] == 'view'
assert responder.directives[1]['payload']['text'] == text
assert responder.directives[1]['name'] == 'speak'

def test_assistant_event(responder: SkillResponder):
expected_name = 'test'
expected_payload = { 'foo': 'bar' }

responder.send_assistant_event(expected_name, expected_payload)

directive = responder.directives[0]

assert directive['name'] == responder.DirectiveNames.ASSISTANT_EVENT
assert directive['payload']['name'] == expected_name
assert directive['payload']['payload'] == expected_payload
15 changes: 15 additions & 0 deletions webex_assistant_sdk/dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class AssistantDirectiveNames(DirectiveNames):
DISPLAY = 'display'
"""A generic display directive."""

ASSISTANT_EVENT = 'assistant-event'
"""A directive to forward a generic payload"""


class DirectiveNotSupportedError(Exception):
pass
Expand Down Expand Up @@ -224,6 +227,18 @@ def long_reply(
if not success:
raise DirectiveNotSupportedError

def send_assistant_event(self, name, payload=None):
"""Sends a 'assistant-event' directive
Args:
name (string): Used to identify the source of the event
payload (json object, optional): Payload to forward
"""
self.act(self.DirectiveNames.ASSISTANT_EVENT, {
'name': name,
'payload': payload,
})

@property
def supported_directives(self):
return [
Expand Down

0 comments on commit 41d52df

Please sign in to comment.