CallCollect
Represents a current or past collect session in a call. You can obtain instances of this class by starting at Collect with the following method:
Example
In this example, we collect digits from the caller. Once the collect session is ended, we print the collected digits and hangup the call.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const voiceClient = client.voice;
const call = await voiceClient.dialPhone({
from: "+YYYYYYYYYY",
to: "+XXXXXXXXXX",
});
// start Collect
await call.collect({
partialResults: true,
sendStartOfInput: true,
digits: {
max: 5,
digitTimeout: 4,
terminators: "#*",
},
listen: {
onStarted: async () => {
console.log("Collect started");
await call.playTTS({
text: "Please enter your PIN"
});
},
onInputStarted: () => {
console.log("Collect input started");
},
onUpdated: (collect) => {
console.log("Collect updated:", collect.digits);
},
onEnded: async (collect) => {
console.log("Collect ended:", collect.result);
console.log("PIN collected:", collect.digits);
call.hangup();
},
onFailed: () => {
console.log("Collect failed")
}
}
}).onStarted();
Properties
confidence
Confidence level for the speech recognition result (if type
is "speech"
), from 0 to 100. For example, 83.2
.
Syntax: CallCollect.confidence()
Returns: number
digits
The digits that have been collected (if type
is "digit"
). For example, "12345"
.
Syntax: CallCollect.digits()
Returns: string
id
The unique id for this collect session.
Syntax: CallCollect.id()
Returns: string
reason
Alias for type
, in case of errors. Use this field to check the reason of the error.
Syntax: CallCollect.reason()
Returns: "no_match"
| "no_input"
| "error"
result
A promise that resolves to the CallCollectResult
object when the collect session is ended
and the result is available.
Syntax: CallCollect.result()
Returns: CallCollectResult
terminator
The terminator used to complete the collect (if type
is "digit"
). For example, "#"
.
Syntax: CallCollect.terminator()
Returns: string
text
The text that has been collected (if type
is "speech"
). For example, "hello who's there"
.
Syntax: CallCollect.text()
Returns: string
type
The type of this collect session.
Syntax: CallCollect.type()
Returns: "error"
| "no_input"
| "no_match"
| "digit"
| "speech"
| "start_of_input"
state
The state of this collect session. Only present when type
is "speech"
and the continuous
parameter
is set to true
. Otherwise, the collect state is always "undefined"
.
Syntax: CallCollect.state()
Returns: "collecting"
| "finished"
| "error"
Methods
ended
▸ ended(): Promise
<CallCollect
>
Returns a promise that is resolved only after this collect finishes (or is stopped).
Returns
Promise
<CallCollect
>
A promise that resolves to the CallCollect
object when the collect session is ended.
Example
const collect = await call.collect({
digits: {
max: 4,
digitTimeout: 10,
terminators: "#",
},
partialResults: true,
sendStartOfInput: true,
}).onStarted();
await collect.ended();
startInputTimers
▸ startInputTimers(): Promise
<CallCollect
>
Start the initialTimeout
timer on an active collect.
Returns
Promise
<CallCollect
>
A promise that resolves to the CallCollect
object when the collect session InputTimer
is started.
Example
const collect = await call.collect({
digits: {
max: 4,
digitTimeout: 10,
terminators: "#",
},
partialResults: true,
sendStartOfInput: true,
startInputTimers: false,
}).onStarted();
// You can add some logic before starting input timers.
await collect.startInputTimers();
stop
▸ stop(): Promise
<CallCollect
>
Stops the collect session.