I have a Teams app that was working end to end when I completed my first cut of it about 18 months ago. It's a messaging extension, and includes a dialog where a user has to make a selection from a drop down and click an OK or Cancel button. The javascript code - which again, was working previously - is now broken and I've been in, around, and all over the interwebs trying to figure out why but am stumped for now. Here are some details:
<script type="text/javascript" src="https://statics.teams.cdn.office.net/sdk/v1.5.2/js/MicrosoftTeams.min.js"></script>
In the dialog form, I have code that looks like this (simplified for this question):
microsoftTeams.initialize();
function validateForm() {
//some stuff here not relevant to the question
var data = {
TenantId: tenantId,
TeamId: teamId,
ChannelId: channelId,
MessageId: messageId,
Op: exportOption
};
microsoftTeams.tasks.submitTask(data, "@Html.Raw(Globals.EXPORT_BOT_APP_ID)");
return true;
}
The problems seem to revolve around the use of "microsoftTeams". When I open the app in a browser and run my app, in the console window I see an error on the "microsoftTeams.initialize();" statement that says reference error - microsoftTeams is not defined. When the validateForm() function runs and it gets to the microsoftTeams.tasks.submitTask method, it also generates an error that says "the library has not yet been initialized".
Of course, I'm looking for the path forward with the least amount of friction. Would appreciate suggestions on how to move this forward into a working state again.
Here's the error info from the browser's console window:
I didn't get the initialize error to go away (the first problem described above), but I did get the callback to start working, which is the important part (the second problem described above). To do that, I had to add a second attribute to my script tag in the layout page. The attribute I added is asp-append-version="true". That makes my script tag look like this:
<script src="https://statics.teams.cdn.office.net/sdk/v1.5.2/js/MicrosoftTeams.min.js" asp-append-version="true"></script>