コード例 #1
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var conversationStateAccessors = ConversationState.CreateProperty <ConversationData>(nameof(ConversationData));
            var conversationData           = await conversationStateAccessors.GetAsync(turnContext, () => new ConversationData());

            // If we have not yet started recording, ask the user the wait.
            if ((turnContext.Activity.ChannelId == "telephony") &&
                (conversationData.RecordingState == RecordingState.Uninitialized))
            {
                var waitText = $"Please wait";

                await turnContext.SendActivityAsync(
                    VoiceFactory.TextAndVoice(waitText, InputHints.IgnoringInput),
                    cancellationToken);

                return;
            }

            // Recording is either started, resumed or paused.
            // We are ready to reply to the bot
            var userText = turnContext.Activity.Text;

            if (string.IsNullOrWhiteSpace(userText))
            {
                return;
            }

            // Echo what the caller says
            //var replyText = $"You said {userText}";
            var replyText = eliza.ProcessInput(userText);
            await turnContext.SendActivityAsync(
                VoiceFactory.TextAndVoice(replyText, InputHints.IgnoringInput),
                cancellationToken);

            // Simple command to test pausing the recording
            if (userText == "pause")
            {
                // Pause only if the recording is active. Ignore the command otherwise.
                if (conversationData.RecordingState == RecordingState.Recording)
                {
                    await RecordingHelpers.TryPauseRecording(turnContext, cancellationToken);
                }
            }

            // Simple command to test resuming the recording
            if (userText == "resume")
            {
                // Resume only if the recording is paused. Ignore the command otherwise.
                if (conversationData.RecordingState == RecordingState.Paused)
                {
                    await RecordingHelpers.TryResumeRecording(turnContext, cancellationToken);
                }
            }
        }
コード例 #2
0
        protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            foreach (var member in membersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    // Welcome message that will not be recorded
                    // Played to minimize initial silence till call recording starts
                    var welcome = "Hello, my name is Eliza. I'm an online therapist";
                    await turnContext.SendActivityAsync(
                        VoiceFactory.TextAndVoice(welcome, InputHints.IgnoringInput),
                        cancellationToken);

                    // Start recording if Telephony channel
                    await RecordingHelpers.TryStartRecording(turnContext, cancellationToken);
                }
            }
        }