team-telnyx / telnyx-dotnet

.NET SDK for the Telnyx API
MIT License
9 stars 9 forks source link

Outdated CallControl exmples? #63

Closed alexkozler closed 6 months ago

alexkozler commented 2 years ago

Seems like some of the examples like this https://github.com/team-telnyx/telnyx-dotnet/blob/master/src/Telnyx.Example/CallControlExample.cs

Are no longer current.

I am wondering how I can use this SDK to string together CallControl commands... For instance if I want to play audio, then speak a TTS sentence consecutively...

Right now I have two functions like this (excuse the VB I know it's gross):

Public Function PlayAudio(sessionID As String, carrierCallID As String, audioURL As String) As Boolean
        Try
            Dim tnyxService As New CallControlPlaybackStartService(sessionID)
            Dim tnyxCommand As New CallControlPlaybackStartOptions With {
                .AudioUrl = audioURL
            }
            tnyxService.Create(carrierCallID, tnyxCommand)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function SpeakSentence(sessionID As String, carrierCallID As String, textToSpeak As String) As Boolean
        Try
            Dim tnyxService As New CallControlSpeakService(sessionID)
            Dim tnyxCommand As New CallControlSpeakOptions With {
                .Payload = textToSpeak,
                .Language = "en-US",
                .Voice = "female"
            }
            tnyxService.Create(carrierCallID, tnyxCommand)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

From what I can see this basically just lets me update a call in progress with a new command. What if I want to string multiple commands at once consecutively?

ADandyGuyInSpace commented 6 months ago

A little late, but you would simply just call them consecutively. You can either use states or webhooks to interact with the call in progress, the call_control_id should be persistent throughout.