Ejemplo n.º 1
0
        public async Task <ConversationActitvities> GetNewestActivities()
        {
            await Task.Delay(TimeSpan.FromMilliseconds(200)).ConfigureAwait(true);

            int inc = 0;
            ConversationActitvities cm = await GetMessages();

            while (++inc < 5)
            {
                Debug.WriteLine(cm.activities.Length + " conversations received");
                for (int i = 0; i < cm.activities.Length; i++)
                {
                    var activity = cm.activities[i];
                    Debug.WriteLine("activity received = " + activity.text);
                    lastResponse = activity.id + " / " + activity.replyToId + " / " + newActivityId;

                    // wait for reply message from my message
                    if (activity.replyToId != null && activity.replyToId.Equals(newActivityId))
                    {
                        Debug.WriteLine("activity is response to " + newActivityId);
                        return(cm);
                    }
                }
                await Task.Delay(TimeSpan.FromMilliseconds(200)).ConfigureAwait(true);

                cm = await GetMessages();
            }
            return(cm);
        }
Ejemplo n.º 2
0
        public async Task <ConversationActitvities> GetMessages()
        {
            using (var client = new HttpClient())
            {
                string conversationId = activeConversation;

                client.BaseAddress = new Uri("https://directline.botframework.com/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // Authorize
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + botToken);

                ConversationActitvities cm = new ConversationActitvities();
                string messageURL          = "v3/directline/conversations/" + conversationId + "/activities";
                if (activeWatermark != null)
                {
                    messageURL += "?watermark=" + activeWatermark;
                }
                HttpResponseMessage response = await client.GetAsync(messageURL);

                if (response.IsSuccessStatusCode)
                {
                    var re = response.Content.ReadAsStringAsync().Result;
                    lastResponse    = re.ToString();
                    cm              = JsonConvert.DeserializeObject <ConversationActitvities>(re);
                    activeWatermark = cm.watermark;
                    return(cm);
                }
                return(cm);
            }
        }
Ejemplo n.º 3
0
        public async Task <string> GetNewestActivity()
        {
            ConversationActitvities cm = await GetNewestActivities();

            if (cm.activities.Length > 0)
            {
                return(cm.activities[cm.activities.Length - 1].text);
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 4
0
        private async void btnAsk_Click(object sender, RoutedEventArgs e)
        {
            string msg          = txtInput.Text;
            string spokenresult = "";

            if (await myBot.SendMessage(msg))
            {
                ConversationActitvities messages = await myBot.GetMessages();

                for (int i = 1; i < messages.activities.Length; i++)
                {
                    lblMessage.Text += messages.activities[i].text + Environment.NewLine;
                    spokenresult    += (messages.activities[i].speak + " ");
                }
                ReadText(spokenresult);
            }
        }