public void Initialize() { // connect to directline client = new Microsoft.Bot.Connector.DirectLine.DirectLineClient(directLineSecret); //if next line shows error, it means no internet / poor connection at start up. conversation = client.Conversations.StartConversation(); }
/// <summary> /// Initializes a new instance of the StreamingConversations class. /// </summary> /// <param name='client'> /// Reference to the service client. /// </param> public StreamingConversations(DirectLineClient client) { if (client == null) { throw new ArgumentNullException("client"); } this.Client = client; }
private async Task <IEnumerable <Activity> > ReadBotMessagesAsync(Microsoft.Bot.Connector.DirectLine.DirectLineClient client, string conversationId) { var activitySet = await client.Conversations.GetActivitiesAsync(conversationId, watermark).ConfigureAwait(false); watermark = activitySet.Watermark; var activities = from x in activitySet.Activities where x.From.Id == botId select x; return(activities); }
private async Task PostToOCSUser(IDialogContext context, Microsoft.Bot.Connector.Activity activity) { Logger.Info($"Agent [{activity.From.Id}] is replying"); var storage = new AgentStatusStorage(ConfigurationHelper.GetString("BotStatusDBConnectionString")); AgentStatus agent = await storage.QueryAgentStatusAsync(activity.From.Id); ConversationRecord conv = (await storage.FindMyConversationActivityAsync(agent.Id)).FirstOrDefault(); var uri = new Uri("https://directline.botframework.com"); Logger.Info($"PostToOCSUser::{agent.Id}/{agent.Name}"); DirectLineClientCredentials creds = new DirectLineClientCredentials(ConfigurationHelper.GetString("OCSBot_DirectLine_Secret")); //lot into the bot framework Microsoft.Bot.Connector.DirectLine.DirectLineClient client = new Microsoft.Bot.Connector.DirectLine.DirectLineClient(uri, creds); //connect the client var conversation = client.Conversations.StartConversation(); DirectLineChannelData data = new DirectLineChannelData() { UserID = conv.RemoteUserId, UserName = conv.RemoteUserName, DirectLineBotID = conv.RemoteBotId }; client.Conversations.PostActivity(conversation.ConversationId, new Microsoft.Bot.Connector.DirectLine.Activity { From = new Microsoft.Bot.Connector.DirectLine.ChannelAccount { Id = agent.Id, Name = $"{agent.Name}@agent" }, Type = Microsoft.Bot.Connector.ActivityTypes.Message, Text = activity.Text, ChannelData = data }); //var remoteConnector = new ConnectorClient( // baseUri: new Uri(remoteActivity.ServiceUrl), // credentials: new MicrosoftAppCredentials( // appId: ConfigurationHelper.GetString("MicrosoftAppId"), // password: ConfigurationHelper.GetString("MicrosoftAppPassword") // ), // addJwtTokenRefresher: true // ); //Logger.Info($"remoteActivity={JsonConvert.SerializeObject(remoteActivity)}"); //remoteConnector.Conversations.SendToConversation(reply); ////reply.From.Name += activity.From.Name + "@agent"; //Logger.Info($"reply created:{JsonConvert.SerializeObject(reply)}"); //remoteConnector.Conversations.ReplyToActivity(reply); //Logger.Info($"replied"); }
private Microsoft.Bot.Connector.DirectLine.DirectLineClient BuildClientFromOptions(DirectLineConnectorOptions options) { var directLineClient = new Microsoft.Bot.Connector.DirectLine.DirectLineClient(options.BotSecret); return(directLineClient); }
public DirectLineConnector(IOptions <DirectLineConnectorOptions> options) { this.options = options?.Value; _directLineClient = BuildClientFromOptions(this.options); }