twilio / twilio-cli-core

Core functionality for the twilio-cli
MIT License
14 stars 32 forks source link

Incorrect schema for Flex interactions #217

Closed vonKingsley closed 1 year ago

vonKingsley commented 1 year ago

Issue Summary

When updating a participant on a Flex Interaction the following error is returned

» Flag value validation errors:
»   sid: "UT1493d308a78395346xxxxxxxxxxxx" does not match pattern "^UO[0-9a-fA-F]{32}$"
    TypeError: Cannot read properties of undefined (reading 'constructor')

Steps to Reproduce

  1. Create a Flex interaction
  2. Add a participant to the interaction
  3. Attempt to update the interaction participant with the following command

Code Snippet

twilio api:flex:v1:interactions:channels:participants:update --channel-sid=UO{32} --interaction-sid=KD{32} --sid=UT{32} --status=closed

Exception/Log

[DEBUG] Config File: /.twilio-cli/config.json
[DEBUG] Using profile: dev
[DEBUG] Schema for "channel-sid": {"type":"string","minLength":34,"maxLength":34,"pattern":"^UO[0-9a-fA-F]{32}$"}
[DEBUG] Schema for "interaction-sid": {"type":"string","minLength":34,"maxLength":34,"pattern":"^KD[0-9a-fA-F]{32}$"}
[DEBUG] Schema for "sid": {"type":"string","minLength":34,"maxLength":34,"pattern":"^UO[0-9a-fA-F]{32}$"}
[DEBUG] Schema for "status": {"type":"string","$ref":"#/components/schemas/interaction_channel_participant_enum_status","description":"The Participant's status. Can be: `closed` or `wrapup`.  Participant must be an agent."}
[DEBUG] Provided flags: {"channel-sid":"UO{32}","interaction-sid":"KD{32}","sid":"UT{32}","status":"closed","cli-output-format":"json","cli-log-level":"debug","silent":false,"skip-parameter-validation":false,"properties":"sid"}

Technical details:

twilio-cli/5.3.3 darwin-x64 node-v16.19.0

Issue can be fixed by changing the pattern here to start with UT

The documentation here shows that the sid for a participant update should have a sid that starts with UT.

kridai commented 1 year ago

Hi @vonKingsley Thanks for reaching out. In the code snippet shared , it seems the api you are using expects the Interaction Channel resource in sid instead of Interaction Channel Participant resource which you are passing currently. It seems like the doc for snippets needs to be updated as well. However if you ru the command twilio api:flex:v1:interactions:channels:participants:update --help you can verify that the api expects Interaction Channel resource in sid. Same is mentioned here in the doc

vonKingsley commented 1 year ago

Thanks @kridai . I believe the docs may be incorrect on that as well as the --help flag. The --help flag states 4 required flags

REQUIRED FLAGS
  --channel-sid=<value>      The Channel Sid for this Participant.
  --interaction-sid=<value>  The Interaction Sid for this channel.
  --sid=<value>              The unique string created by Twilio to identify an Interaction Channel resource.
  --status=<value>           The Participant's status. Can be: `closed` or `wrapup`.  Participant must be an agent.

Since we are updating the Interactions Channel Participant endpoint, I'm not sure why the main --sid would use the Interactions Channel resource, and not the Interactions Channel Participant resource? I believe it should be the following

--channel-sid, This should be the Interaction Channel Resource --UO
--interaction-sid,  for the Flex interaction --KD
--sid, This should be the Interactions Channel Participant resource --UT 

Also I want to mention that using python or node libraries this is actually the correct way to call this API endpoint with a sid that starts with UT

channel = twilio.fetch_interaction("KD{32}").channels("UO{32}")
print('hey', channel.participants.list())

-> [<Twilio.FlexApi.V1.InteractionChannelParticipantInstance interaction_sid=KD{32} channel_sid=UO{32} sid=**UT**{32}>, <Twilio.FlexApi.V1.InteractionChannelParticipantInstance interaction_sid=KD{32} channel_sid=UO{32} sid=**UT**{32}>]

channel.participants("**UT**{32}").update(status="closed")
AsabuHere commented 1 year ago

Hi @vonKingsley , In order to properly debug this issue, please file a support ticket.

As a temporary workaround, you can pass the --skip-parameter-validation flag:

--skip-parameter-validation Skips client-side parameter validation. Useful for debugging when twilio-cli is being overly-aggressive in validating parameter values.

Applies to the `twilio login`, `twilio profiles:add`, and all `twilio api` sub-commands.