Ejemplo n.º 1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string secretout = appid + ":" + secret;
                var    uri       = new Uri("https://directline.botframework.com");

                string newsecret = "zHhveP4jk4o.cwA.cIA.QERY2t7safaD557XAYfyFp0WZrpQji3s2nI7QbPunSQ";

                DirectLineClientCredentials creds = new DirectLineClientCredentials(newsecret);

                DirectLineClient client = new DirectLineClient(uri, creds);
                Microsoft.Bot.Connector.DirectLine.Conversations convs = new Microsoft.Bot.Connector.DirectLine.Conversations(client);

                string waterMark;

                var conv = convs.NewConversation();
                var set  = convs.GetMessages(conv.ConversationId);
                waterMark = set.Watermark;

                Microsoft.Bot.Connector.DirectLine.Models.Message message = new Microsoft.Bot.Connector.DirectLine.Models.Message(conversationId: conv.ConversationId, text: textBox1.Text);
                //Console.WriteLine(message.Text);
                convs.PostMessage(conv.ConversationId, message);

                set = convs.GetMessages(conv.ConversationId, waterMark);
                PrintResponse(set);
                waterMark = set.Watermark;

                string x = await MakeRequest(textBox1.Text);

                //System.Threading.Thread.Sleep(15000);

                if (x != String.Empty)
                {
                    textBox2.Text += " Return JSON: " + x + System.Environment.NewLine;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                string secretout = appid + ":" + secret;
                //var uri = new Uri("https://directline.botframework.com");
                var uri = new Uri(ConfigurationManager.AppSettings["DirectLineURL"].ToString());

                //string newsecret = "zHhveP4jk4o.cwA.cIA.QERY2t7safaD557XAYfyFp0WZrpQji3s2nI7QbPunSQ";

                string newsecret = ConfigurationManager.AppSettings["DirectLineSecret"].ToString();

                DirectLineClientCredentials creds = new DirectLineClientCredentials(newsecret);

                DirectLineClient client = new DirectLineClient(uri, creds);
                Microsoft.Bot.Connector.DirectLine.Conversations convs = new Microsoft.Bot.Connector.DirectLine.Conversations(client);

                string waterMark;

                var conv = convs.NewConversation();
                var set  = convs.GetMessages(conv.ConversationId);
                waterMark = set.Watermark;

                Microsoft.Bot.Connector.DirectLine.Models.Message message = new Microsoft.Bot.Connector.DirectLine.Models.Message(conversationId: conv.ConversationId, text: textBox1.Text);
                //Console.WriteLine(message.Text);
                convs.PostMessage(conv.ConversationId, message);

                set = convs.GetMessages(conv.ConversationId, waterMark);
                PrintResponse(set);
                waterMark = set.Watermark;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private async Task <Microsoft.Bot.Connector.DirectLine.Activity> PostToAgentBotAsync(Microsoft.Bot.Connector.DirectLine.Activity activityFromUser)
        {
            var directLineSecret = Configuration.ConfigurationHelper.GetString("AgentBot_DirectLine_Secret");
            var agentStatusDB    = Configuration.ConfigurationHelper.GetString("BotStatusDBConnectionString");
            var dc           = new DirectLineClient(directLineSecret);
            var agentStorage = new AgentStatusStorage(agentStatusDB);
            var agent        = await agentStorage.QueryAgentStatusAsync(activityFromUser.Recipient.Id);

            ConversationStatus convStatus = null;

            //var agentConversations = await agentStorage.QueryConversationStatusAsync(agent.Id);

            try
            {
                var uri = new Uri("https://directline.botframework.com");
                DirectLineClientCredentials creds  = new DirectLineClientCredentials(directLineSecret);                                //lot into the bot framework
                DirectLineClient            client = new DirectLineClient(uri, creds);                                                 //connect the client
                Microsoft.Bot.Connector.DirectLine.Conversations convs = new Microsoft.Bot.Connector.DirectLine.Conversations(client); //get the list of conversations belonging to the bot? Or does this start a new collection of conversations?

                Microsoft.Bot.Connector.DirectLine.Conversation conversation = null;
                if (string.IsNullOrEmpty(_agentConversationId))
                {
                    conversation         = dc.Conversations.StartConversation();
                    _agentConversationId = conversation.ConversationId;
                }
                else
                {
                    conversation = new Microsoft.Bot.Connector.DirectLine.Conversation()
                    {
                        ConversationId = _agentConversationId,
                    };
                }
                Logger.Info($"activityFromUser - From.Name:{activityFromUser.From.Name} - From.Id:{activityFromUser.From.Id}");
                Logger.Info($"activityFromUser - Recipient.Name:{activityFromUser.Recipient.Name} - Recipient.Id:{activityFromUser.Recipient.Name}");
                var toAgent = new Microsoft.Bot.Connector.DirectLine.Activity
                {
                    Type = Microsoft.Bot.Connector.DirectLine.ActivityTypes.Message,
                    Text = activityFromUser.Text,
                    From = new Microsoft.Bot.Connector.DirectLine.ChannelAccount
                    {
                        Id   = activityFromUser.From.Id,/*activityFromUser.From.Id,*/
                        Name = $"{activityFromUser.From.Name}@ocsuser"
                    },
                    Recipient   = activityFromUser.Recipient,
                    ChannelId   = agent.ChannelId,
                    ChannelData = new DirectLineChannelData
                    {
                        RoundTrip      = 0,
                        ConversationId = _agentConversationId,
                        UserID         = activityFromUser.From.Id,
                        UserName       = activityFromUser.From.Name
                    }
                };

                var resp = await dc.Conversations.PostActivityAsync(
                    conversation.ConversationId,
                    toAgent);

                Logger.Info($"OCSBot::Dialog:PostToAgent() - {JsonConvert.SerializeObject(toAgent)}");
                //convStatus = (await agentStorage.QueryConversationStatusAsync(agent.Id)).OrderByDescending(o => o.Timestamp).FirstOrDefault();
                //convStatus.OCSDirectlineConversationId = conversation.ConversationId;
                //convStatus.OCSEndUserId = activityFromUser.From.Id;
                //convStatus.OCSEndUserName = activityFromUser.From.Name;
                //convStatus.OCSBotName = activityFromUser.Recipient.Name;
                //convStatus.OCSBotId = activityFromUser.Recipient.Id;
                //await agentStorage.UpdateConversationStatusAsync(convStatus);
                return(null);
            }
            catch (Exception exp)
            {
                Logger.Info($"OCSBot::PostToAgent() - Exception while posting to Agent:{exp.Message}");
                throw;
            }
        }