I am trying to display data in a tabular format on Teams with the bot framework.
First, I used an adaptive card following this example. It works fine but when the items become so many there's no support for scrollbar (both vertical and horizontal).
I later wrote an HTML table as a string and passed it to the activity text. This works very well but does not work for large data sets. I got the error: Request Entity Too Large.
How can I resolve this, please?
public static string ConvertToHTMLString(DataTable dt)
{
StringBuilder sb = new StringBuilder();
sb.Append("<table style='border-collapse: collapse;font-family: Arial, Helvetica, sans-serif; width: 100%;'>");
sb.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
sb.Append("<th style='border: 1px solid #ddd; padding: 8px;padding-top: 12px;padding-bottom: 12px;text-align: left;background-color: #4CAF50;color: white;'>" + column.ColumnName + "</th>");
}
sb.Append("</tr>");
foreach (DataRow row in dt.Rows)
{
sb.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
sb.Append("<td style='border: 1px solid #ddd; padding: 8px;'>" + row[column.ColumnName].ToString() + "</td>");
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, ancellationToken cancellationToken)
{
var activity = Activity.CreateMessageActivity();
activity.TextFormat = "XML";
activity.Text = ConvertToHTMLString();
await turnContext.SendActivityAsync(activity, cancellationToken);
}
There's a maximum message size in bot framework / MS Teams.
You'r messages (Cards, whatever) can not be larger than 25kb for a single message. Thats why you receive this error. You'r message is just too large.
Only available fix would be reducing the size, remove not needed things or split it into multiple messages.