Skip to content

Commit

Permalink
Meet the expecation of path for c# streaming client
Browse files Browse the repository at this point in the history
  • Loading branch information
boydc2014 committed May 25, 2024
1 parent 77d05c8 commit 2bf1785
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,14 @@ private async Task<StreamingResponse> ProcessCreateConversationRequestAsync(Rece

return streamResponse;
}

private async Task<StreamingResponse> ProcessPostActivityRequestAsync(ReceiveRequest request, ILogger<RequestHandler> logger, object context, string conversationId, ChannelAccount user, CancellationToken cancellationToken)
{
var activity = await request.ReadBodyAsJsonAsync<Activity>().ConfigureAwait(false);
activity.Conversation = new ConversationAccount { Id = conversationId };
activity.Id = Guid.NewGuid().ToString();
activity.Timestamp = DateTime.UtcNow;
activity.Recipient = new ChannelAccount { Id = "bot", Name = "bot" };

// Echo back the activity to client first, so the client knows the activity has been received
await SendActivityToClient(request, activity, logger, cancellationToken);
Expand All @@ -247,7 +248,7 @@ private async Task<InvokeResponse> SendConversationUpdateToBotAsync(ReceiveReque
Timestamp = DateTime.UtcNow,
ChannelId = channelId,
Conversation = new ConversationAccount { Id = conversationId },
Recipient = new ChannelAccount { Id = "Bot", Name = "Bot" },
Recipient = new ChannelAccount { Id = "bot", Name = "bot" },
From = _user
};
return await SendActivityToBot(requestContext, update, logger, cancellationToken);
Expand All @@ -269,7 +270,8 @@ private async Task<ReceiveResponse> SendActivityToClient(ReceiveRequest requestC
{
var clientRequest = new StreamingRequest
{
Path = requestContext.Path,
// Stream client is expecting the path to be relative to /v3/directline
Path = requestContext.Path.Replace("/v3/directline", ""),
Verb = requestContext.Verb
};
var activitySet = new ActivitySet
Expand Down Expand Up @@ -333,16 +335,20 @@ private async Task<StreamingRequest> CreateSteamingRequestAsync(HttpRequestMessa
{
var streamingRequest = new StreamingRequest
{
Path = httpRequestMessage.RequestUri.OriginalString.Substring(httpRequestMessage.RequestUri.OriginalString.IndexOf("/v3", StringComparison.Ordinal)),
Path = httpRequestMessage.RequestUri.OriginalString.Substring(httpRequestMessage.RequestUri.OriginalString.IndexOf("/conversation", StringComparison.Ordinal)),
Verb = httpRequestMessage.Method.ToString(),
};

// Stream client doesn't expect the path to contains any thing after activities
streamingRequest.Path = streamingRequest.Path.Substring(0, streamingRequest.Path.IndexOf("activities", StringComparison.Ordinal) + "activities".Length);

if (httpRequestMessage.Content != null)
{
var contentString = await httpRequestMessage.Content.ReadAsStringAsync();
var activity = JsonConvert.DeserializeObject<Activity>(contentString);
activity.Timestamp = DateTime.UtcNow;
activity.Id = Guid.NewGuid().ToString();
activity.From = new ChannelAccount { Id = "bot", Name = "bot" };

var activitySet = new
{
Expand Down

0 comments on commit 2bf1785

Please sign in to comment.