Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling.call.received event handlers #536

Merged
merged 4 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/curly-years-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sw-internal/playground-realtime-api': patch
'@signalwire/realtime-api': patch
---

Fix calling.call.received event handler
48 changes: 48 additions & 0 deletions internal/playground-realtime-api/src/voice-inbound/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Voice } from '@signalwire/realtime-api'

async function run() {
try {
const client = new Voice.Client({
host: process.env.HOST || 'relay.swire.io',
project: process.env.PROJECT as string,
token: process.env.TOKEN as string,
contexts: [process.env.RELAY_CONTEXT as string],
// logLevel: 'trace',
debug: {
logWsTraffic: true,
},
})

client.on('call.received', async (call) => {
console.log('Got call', call.id, call.from, call.to, call.direction)

try {
await call.answer()
console.log('Inbound call answered')

const pb = await call.playTTS({
text: "Hello! Welcome to Knee Rub's Weather Helpline. What place would you like to know the weather of?",
gender: 'male',
})
await pb.waitForEnded()
console.log('Welcome text ok')

const prompt = await call.promptTTS({
text: 'Please enter 1 for Washington, 2 for California, 3 for washington weather message, 4 for california weather message, 5 if your tribe beeds to do a rain dance, 6 for me to call your friends who need to rain dance.',
digits: {
max: 1,
digitTimeout: 15,
},
})
const { type, digits, terminator } = await prompt.waitForResult()
console.log('Received digits', type, digits, terminator)
} catch (error) {
console.error('Error answering inbound call', error)
}
})
} catch (error) {
console.log('<Error>', error)
}
}

run()
2 changes: 0 additions & 2 deletions packages/realtime-api/src/voice/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export class CallConsumer extends AutoApplyTransformsConsumer<RealTimeCallApiEve
// @ts-expect-error
return this.device?.params?.from ?? ''
}
this.logger.warn('Unknow Call type', this.type)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@framini i removed these warns before the proxy serializeableProxy->getAllMethods is invoking all the getters generating a lot of "useless" warnings.

// @ts-expect-error
return this.device?.params?.from ?? ''
}
Expand All @@ -197,7 +196,6 @@ export class CallConsumer extends AutoApplyTransformsConsumer<RealTimeCallApiEve
// @ts-expect-error
return this.device?.params?.to ?? ''
}
this.logger.warn('Unknow Call type', this.type)
// @ts-expect-error
return this.device?.params?.to ?? ''
}
Expand Down
1 change: 1 addition & 0 deletions packages/realtime-api/src/voice/Voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class VoiceAPI extends AutoApplyTransformsConsumer<RealTimeVoiceApiEvents> {
[
'calling.call.received',
{
mode: 'no-cache',
type: 'voiceCallReceived',
instanceFactory: (_payload: any) => {
return createCallObject({
Expand Down