Search code examples
c#asp.net-corebotframeworkmicrosoft-teams

Attaching CSV file to reply for Microsoft Bot Framework for Teams


I am creating a bot that needs to return a csv file from an azure storage blob as a response (i.e. give me a listing of all users and email addresses). When I run the request in the bot framework emulator it works great, but when trying in teams (which will be used for the chatbot) I get the following error.

Operation returned an invalid status code 'BadRequest' at Microsoft.Bot.Connector.Conversations.ReplyToActivityWithHttpMessagesAsync(String conversationId, String activityId, Activity activity, Dictionary2 customHeaders, CancellationToken cancellationToken) at Microsoft.Bot.Connector.ConversationsExtensions.ReplyToActivityAsync(IConversations operations, String conversationId, String activityId, Activity activity, CancellationToken cancellationToken) at Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken) at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass25_0.<g__SendActivitiesThroughAdapter|1>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(IActivity activity, CancellationToken cancellationToken).

Here is the part where I an attaching the file to the message.

var message = MessageFactory.Text(noOfUsersFoundText, noOfUsersFound, InputHints.IgnoringInput);
message.Attachments.Add(new Attachment
{
    Name = fileName,
    ContentType = "text/csv",
    ContentUrl = fileUrl
});
await stepContext.Context.SendActivityAsync(message, cancellationToken);

Has any one gotten this to work?

UPDATE: This is from the App Studio Editor in teams.

enter image description here


Solution

  • Ok from what I read, only image files can be used as attachments. So I went with sending a hero card to the url. And that seems to work.