Example #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.Log(cm.activities.Length + " conversations received");
                for (int i = 0; i < cm.activities.Length; i++)
                {
                    var activity = cm.activities[i];
                    Debug.Log("activity received = " + (string)activity["text"]);
                    lastResponse = (string)activity["id"] + " / " + (string)activity["replyToId"] + " / " + newActivityId;

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

                cm = await GetMessages();
            }
            return(cm);
        }
Example #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);
            }
        }
Example #3
0
        public async Task <string> GetNewestActivity()
        {
            ConversationActitvities cm = await GetNewestActivities();

            if (cm.activities.Length > 0)
            {
                return((string)cm.activities[cm.activities.Length - 1]["text"]);
            }
            else
            {
                return("");
            }
        }