public async Task OnPostSendMessageAsync(string connectionId, string text) { var context = new DefaultAgentContext { Wallet = await _walletService.GetWalletAsync(_walletOptions.WalletConfiguration, _walletOptions.WalletCredentials) }; var sentTime = DateTime.UtcNow; var messageRecord = new BasicMessageRecord { Id = Guid.NewGuid().ToString(), Direction = MessageDirection.Outgoing, Text = text, SentTime = sentTime, ConnectionId = connectionId }; var message = new BasicMessage { Content = text, SentTime = sentTime.ToString("s", CultureInfo.InvariantCulture) }; var connection = await _connectionService.GetAsync(context, connectionId); // Save the outgoing message to the local wallet for chat history purposes await _recordService.AddAsync(context.Wallet, messageRecord); // Send an agent message using the secure connection await _messageService.SendAsync(context.Wallet, message, connection); }
public async Task <SendMessageResponse> Handle ( SendMessageRequest aSendMessageRequest, CancellationToken aCancellationToken ) { var defaultAgentContext = new DefaultAgentContext { Wallet = await WalletService.GetWalletAsync(AgentOptions.WalletConfiguration, AgentOptions.WalletCredentials) }; DateTime sentTime = DateTime.UtcNow; var messageRecord = new BasicMessageRecord { Id = Guid.NewGuid().ToString(), Direction = MessageDirection.Outgoing, Text = aSendMessageRequest.Message, SentTime = sentTime, ConnectionId = aSendMessageRequest.ConnectionId }; var basicMessage = new BasicMessage(defaultAgentContext.UseMessageTypesHttps) { Content = aSendMessageRequest.Message, SentTime = sentTime.ToString("s", CultureInfo.InvariantCulture) }; ConnectionRecord connectionRecord = await ConnectionService.GetAsync(defaultAgentContext, aSendMessageRequest.ConnectionId); // Save the outgoing message to the local wallet for chat history purposes await WalletRecordService.AddAsync(defaultAgentContext.Wallet, messageRecord); // Send an agent message using the secure connection await MessageService.SendAsync(defaultAgentContext, basicMessage, connectionRecord); var response = new SendMessageResponse(aSendMessageRequest.CorrelationId); return(response); }
public async Task <IActionResult> SendMessage(string connectionId, string text) { if (string.IsNullOrEmpty(text)) { return(RedirectToAction("Details", new { id = connectionId })); } var context = new AgentContext { Wallet = await _walletService.GetWalletAsync(_walletOptions.WalletConfiguration, _walletOptions.WalletCredentials) }; var sentTime = DateTime.UtcNow; var messageRecord = new BasicMessageRecord { Id = Guid.NewGuid().ToString(), Direction = MessageDirection.Outgoing, Text = text, SentTime = sentTime, ConnectionId = connectionId }; var message = new BasicMessage { Content = text, SentTime = sentTime.ToString("s", CultureInfo.InvariantCulture) }; var connection = await _connectionService.GetAsync(context, connectionId); // Save the outgoing message to the local wallet for chat history purposes await _recordService.AddAsync(context.Wallet, messageRecord); // Send an agent message using the secure connection await _messageService.SendToConnectionAsync(context.Wallet, message, connection); return(RedirectToAction("Details", new { id = connectionId })); }