Ejemplo n.º 1
0
        async public static Task GetIM_Step05_Event_Send_Msg(HttpClient httpClient, string message)
        {
            try
            {
                httpClient.DefaultRequestHeaders.Remove("Accept");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ConfigData.ucwaAuthenticationResult.AccessToken);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

                string url_00 = ConfigData.ucwaApplicationsHost + ConfigData.ucwaEvents;

                ConfigData.Log("1", String.Format("Step 05 : GET : {0}", url_00));

                ConfigData.Log("5", String.Format(">> Request: {0}", "GET"));
                ConfigData.Log("5", String.Format(">> URL: {0}", url_00));

                var res_00 = await httpClient.GetAsync(url_00);

                string res_00_request = res_00.RequestMessage.ToString();
                string res_00_headers = res_00.Headers.ToString();
                string res_00_status  = res_00.StatusCode.ToString();
                var    res_00_content = await res_00.Content.ReadAsStringAsync();


                ConfigData.Log("5", String.Format(">> Response: {0}", res_00_status));
                ConfigData.Log("5", String.Format("{0}", res_00_headers));
                ConfigData.Log("5", String.Format("\r\n{0}", res_00_content));

                if (res_00_status == "OK")
                {
                    SendMessageRoot obj = new SendMessageRoot();
                    JsonConvert.PopulateObject(res_00_content, obj);
                    if (obj != null)
                    {
                        if (obj._links != null)
                        {
                            ConfigData.ucwaEvents = obj._links.next.href;
                        }

                        List <UcwaSfboConsole5.Sender> senders = obj.sender.FindAll(x => x.rel.Equals("conversation") && x.events.Find(e => e._embedded != null && e._embedded.messaging != null && e._embedded.messaging._links != null && e._embedded.messaging._links.sendMessage != null) != null);
                        if (senders != null && senders.Count > 0)
                        {
                            string msgUrl = senders[0].events[0].link.href;
                            await UcwaSendMessage.SendIM_Step05(httpClient, "echo " + message, msgUrl);
                        }
                    }

                    // GetIM_Step03_Events(httpClient);
                }
                else
                {
                    ConfigData.Log("2", String.Format(">> SendIM ended abnormally. {0}", "STEP05"));
                }
            }
            catch (Exception ex)
            {
                ConfigData.Log("2", String.Format(">> Error in step 05. {0}", ex.InnerException.Message));
            }
        }
Ejemplo n.º 2
0
 public async Task PostAsync(IMessageActivity message, CancellationToken cancellationToken = default(CancellationToken))
 {
     var sendMessageUrl = message.ChannelData as string;
     await UcwaSendMessage.SendIM_Step05(Program.httpClient, message.Text, sendMessageUrl);
 }