private void SendActivity_Click(object sender, RoutedEventArgs e)
        {
            string speakActivity = CustomActivityTextbox.Text;

            dialogServiceConnector.SendActivityAsync(speakActivity);

            var activity = JsonConvert.DeserializeObject <Activity>(speakActivity);

            UpdateUI(() =>
            {
                this.Activities.Add(new ActivityDisplay(speakActivity, activity, Sender.User));
            });
        }
Ejemplo n.º 2
0
        public async Task SendDirectLineSpeechTextMessage()
        {
            GetEnvironmentVars();

            echoGuid = Guid.NewGuid().ToString();
            input   += echoGuid;

            // Create a Dialog Service Config for use with the Direct Line Speech Connector
            var config = DialogServiceConfig.FromBotSecret(speechBotSecret, speechSubscription, speechRegion);

            config.SpeechRecognitionLanguage = "en-us";
            config.SetProperty(PropertyId.Conversation_From_Id, FromUser);

            // Create a new Dialog Service Connector for the above configuration and register to receive events
            var connector = new DialogServiceConnector(config, AudioConfig.FromWavFileInput(soundFilePath));

            connector.ActivityReceived += Connector_ActivityReceived;

            // Open a connection to Direct Line Speech channel. No await because the call will block until the connection closes.
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            connector.ConnectAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            // Create a message activity with the input text.
            var userMessage = new Activity
            {
                From = new ChannelAccount(FromUser),
                Text = input,
                Type = ActivityTypes.Message,
            };

            // Send the message activity to the bot.
            await connector.SendActivityAsync(JsonConvert.SerializeObject(userMessage));

            // Give the bot time to respond.
            System.Threading.Thread.Sleep(1000);

            // Read the bot's message.
            var botAnswer = messages.LastOrDefault();

            // Cleanup
            await connector.DisconnectAsync();

            connector.Dispose();

            // Assert
            Assert.IsNotNull(botAnswer);
            Assert.AreEqual(string.Format("You said '{0}'", input), botAnswer.Message);
        }
Ejemplo n.º 3
0
        private async void StatusBox_KeyUp(object sender, KeyEventArgs e)
        {
            StopPlayback();
            waitingForUserInput = false;

            if (e.Key == Key.Enter)
            {
                e.Handled = true;

                var activity = Activity.CreateMessageActivity();
                activity.Text = statusBox.Text;

                statusBox.Clear();
                var jsonConnectorActivity = JsonConvert.SerializeObject(activity);

                AddMessage(new MessageDisplay(activity.Text, Sender.User));
                var id = await connector.SendActivityAsync(jsonConnectorActivity);

                Debug.WriteLine($"SendActivityAsync called, id = {id}");
            }
        }
Ejemplo n.º 4
0
        private async void ListenButton_ButtonClicked(object sender, RoutedEventArgs e)
        {
            if (connector == null)
            {
                InitializeDialogServiceConnector();
                // Optional step to speed up first interaction: if not called, connection happens automatically on first use
                var connectTask = connector.ConnectAsync();
            }

            try
            {
                // Start sending audio to your speech-enabled bot
                var listenTask = connector.ListenOnceAsync();

                // You can also send activities to your bot as JSON strings -- Microsoft.Bot.Schema can simplify this
                string speakActivity = @"{""type"":""message"",""text"":""Greeting Message"", ""speak"":""Hello there!""}";
                await connector.SendActivityAsync(speakActivity);
            }
            catch (Exception ex)
            {
                NotifyUser($"Exception: {ex.ToString()}", NotifyType.ErrorMessage);
            }
        }