Reputation: 23
I am trying to simulate user input with Twilio so I can test our voice system using RSpec. I can create a new call, but the official Twilio ruby gem doesn't seem to allow me to send digits the way a user could type them.
@client = Twilio::REST::Client.new(account_sid, auth_token)
call = @client.calls.create({
from: '+1555550000',
to: '+15555559999',
url: 'www.example.com/twilio-endpoint'
})
This returns a call object which I would expect you could send digits to, but you can't. You can send digits when starting the call by passing a :send_digits
key, but once it's been started, you're out of luck. We need to interact with the phone menu and so forth.
There's a gem called Twilio Test Kit that used to make this easy, but it was abandoned by its maintainer ages ago. What are people doing to feature test their Twilio voice apps?
Update: I should have added this to the original post -- but I am looking to write feature tests that may look something like
expect(call).to play_voice_recording('path/to/recording.wav')
call.dial(123)
expect(call).to say('confirmed successfully')
call.dial(0)
expect(call).to say('transferring to operator')
Upvotes: 1
Views: 277
Reputation: 73065
Twilio developer evangelist here.
The call object is really a wrapper around a call resource in the REST API. You can update a call's state using the REST API, but that only allows you to redirect the call to another URL that returns TwiML or cancel or complete the call.
Presumably your /twilio-endpoint
is returning TwiML that includes a <Gather>
that you are trying to test the user response to. When a user enters digits in the phone in response to that <Gather>
the next action is for Twilio to POST those digits to the action
attribute of the <Gather>
. So to test what happens next, you need to send a POST request to the URL you use as the action
attribute with the entered digits set as the parameter Digits
.
Let me know if this helps at all.
Upvotes: 0