I have included middleware to log the chats in firebase db. Now I am able to call the middleware once after the user sends some text to the bot then after bot sends the data to the user. In the previous version bot framework v3 the activity payload will change the message.text and from and to as user-bot/bot-user. But now in bot framework v4 when the bot sends message/response to the user I can't find the data sent anywhere in the payload. Is there a way to save the data from bot-user. Please suggest me any ideas.
Asked
Active
Viewed 279 times
1 Answers
2
If you want to get in the middle of activities being sent outwards from the bot from a piece of middleware you would want to hook into the ITurnContext::OnSendActivities
like so:
public class MyActivityLoggingMiddleware : IMiddleware
{
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
{
// log incoming activity from turnContext.Activity here
// Hook the turn context's OnSendActivities
turnContext.OnSendActivities(HandleSendActivities);
await next(cancellationToken);
}
private async Task<ResourceResponse[]> HandleSendActivities(ITurnContext turnContext, List<Activity> activities, Func<Task<ResourceResponse[]>> next)
{
// log activities being sent here
return await next();
}
}

Drew Marsh
- 33,111
- 3
- 82
- 100
-
@DevaNarayanan No problem! How about an upvote or marking as the answer to help other people out in the future? – Drew Marsh Jan 08 '19 at 22:44
-
1already did but my reputation is less than 15 thats why commented :laugh: – Deva Narayanan Jan 09 '19 at 06:11