botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Saving Bot Activities in Azure SQL Database not working.

Open JeevaJose opened this issue 9 years ago • 3 comments

I am working on new bot feature to save the bot activities in azure data base. I have done all the required configuration as mentioned on the bot framework web site https://blog.botframework.com/2017/05/05/Saving-Bot-Actions-On-Azure-Sql-Server/. If I send the message from emulator it was failing and throwing the error message.

Looks the below code functionality is incomplete. I think LogAsync function is return null because of that application is throwing null reference error. Could you please help me to fix this issue.

public class EntityFrameworkActivityLogger : IActivityLogger
{        
    Task IActivityLogger.LogAsync(IActivity activity)
    {
        IMessageActivity msg = activity.AsMessageActivity();

        using (Data.ConversationDataContext dataContext = new Data.ConversationDataContext())
        {
            var newActivity = Mapper.Map<IMessageActivity, Data.Activity>(msg);
            if (string.IsNullOrEmpty(newActivity.Id))
                newActivity.Id = Guid.NewGuid().ToString();

            dataContext.Activities.Add(newActivity);
            dataContext.SaveChanges();
        }
        return null;
    }
}

JeevaJose avatar May 13 '17 15:05 JeevaJose

Try

return Task.FromResult(0);

EricDahlvang avatar May 13 '17 17:05 EricDahlvang

now it is working.

JeevaJose avatar May 14 '17 10:05 JeevaJose

@JeevaJose Please close the issue

amitbend avatar May 14 '17 12:05 amitbend