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); } } }
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()); // Wait for recording to start. if ((TelephonyExtensions.IsTelephonyChannel(turnContext.Activity.ChannelId)) && (conversationData.RecordingState == RecordingState.Uninitialized)) { var waitText = $"Please wait while your call is setup."; await turnContext.SendActivityAsync( VoiceFactory.TextAndVoiceNoBargeIn(waitText), cancellationToken); return; } var userText = turnContext.Activity.Text; if (string.IsNullOrWhiteSpace(userText)) { return; } // Echo what the caller says string replyText = $"You said {userText}"; await turnContext.SendActivityAsync( VoiceFactory.TextAndVoice(replyText), cancellationToken); }
protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) { foreach (var member in membersAdded) { // Greet anyone that was not the target (recipient) of this message. if (member.Id != turnContext.Activity.Recipient.Id) { var response = VoiceFactory.TextAndVoice($"Welcome to {CompanyName}!"); await turnContext.SendActivityAsync(response, cancellationToken); await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>("DialogState"), cancellationToken); } } }