Skip to content

Commit

Permalink
change response message
Browse files Browse the repository at this point in the history
  • Loading branch information
ajar98 committed Jul 9, 2024
1 parent 766259d commit 6a39c4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/streaming/action/test_dtmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,4 @@ async def test_twilio_dtmf_failure(
)

assert not action_output.response.success
assert action_output.response.message == "Invalid DTMF buttons, can only accept 0-9"
14 changes: 11 additions & 3 deletions vocode/streaming/action/dtmf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Type
from typing import List, Optional, Type

from loguru import logger
from pydantic.v1 import BaseModel, Field
Expand All @@ -22,6 +22,7 @@ class DTMFParameters(BaseModel):

class DTMFResponse(BaseModel):
success: bool
message: Optional[str] = None


class DTMFVocodeActionConfig(VocodeActionConfig, type="action_dtmf"): # type: ignore
Expand All @@ -32,7 +33,12 @@ def action_attempt_to_string(self, input: ActionInput) -> str:
def action_result_to_string(self, input: ActionInput, output: ActionOutput) -> str:
assert isinstance(input.params, DTMFParameters)
assert isinstance(output.response, DTMFResponse)
return f"Pressed numbers {list(input.params.buttons)} successfully"
if output.response.success:
return f"Pressed numbers {list(input.params.buttons)} successfully"
else:
return (
f"Failed to press numbers {list(input.params.buttons)}: {output.response.message}"
)


FUNCTION_DESCRIPTION = "Presses a string numbers using DTMF tones."
Expand Down Expand Up @@ -85,7 +91,9 @@ async def run(self, action_input: ActionInput[DTMFParameters]) -> ActionOutput[D
logger.warning(f"Invalid DTMF buttons: {buttons}")
return ActionOutput(
action_type=action_input.action_config.type,
response=DTMFResponse(success=False),
response=DTMFResponse(
success=False, message="Invalid DTMF buttons, can only accept 0-9"
),
)
self.conversation_state_manager._twilio_phone_conversation.output_device.send_dtmf_tones(
keypad_entries=keypad_entries
Expand Down

0 comments on commit 6a39c4b

Please sign in to comment.