如何修复:Microsoft Teams'从连接器收到错误'

时间:2019-07-11 12:20:05

标签: c# razor microsoft-teams

我正在为个人应用程序中的团队开发自定义连接器。保存时,出现以下错误:“无法保存”连接器配置”,
并在控制台中显示: Console Error 我遵循了Microsoft示例,这是setup.cshtml:

"microsoftTeams.settings.registerOnSaveHandler(function (saveEvent) {
    microsoftTeams.getContext(function (context) {
        url = "https://mydomain.azurewebsites.net/Connector/Setup.cshtml";
        entity = 'connector-officedev-' + context.teamId + '-' + context.channelId;

        microsoftTeams.settings.setSettings({
            entityId: entity,
            contentUrl: url,
            configName: entity
        });
    });
    microsoftTeams.settings.getSettings(function (settings) {
        //var webhookUrl = settings.webhookUrl;
        $.ajax({
            url: 'Save',
            type: 'POST',
            contentType: 'application/json',
            data:  JSON.stringify({ urlwebhook :settings.webhookUrl }),
            success: function (data) {
                $("#webhookUrl").text(data);
                console.log('webhook created successfully.');
            },
            error: function (errorThrown) {
                $("#webhookUrl").text("Error");
                console.log('error', errorThrown);
            }
        });

    });

    saveEvent.notifySuccess();
});
microsoftTeams.settings.registerOnRemoveHandler(function (removeEvent) {
    var removeCalled = true;
});"

在Connector Developer仪表板的有效域中,我有“ https://mydomain.azurewebsites.net/Connector/Setup.cshtml” 我不知道为什么它不起作用 谢谢您的帮助

更新1 在“保存”的第一个提示上,有错误,但是在第二个提示上,它正在工作,我可以向网络挂接发送消息

更新解决方案 我找到了解决方案saveEvent.notifySucess();必须在ajax调用的成功函数中,例如:

$.ajax({
        url: 'Save',
        type: 'POST',
        contentType: 'application/json',
        data:  JSON.stringify({ urlwebhook :settings.webhookUrl }),
        success: function (data) {
            $("#webhookUrl").text(data);
            console.log('webhook created successfully.');
            saveEvent.notifySuccess();
        },
        error: function (errorThrown) {
            $("#webhookUrl").text("Error");
            console.log('error', errorThrown);
            saveEvent.notifyFailure("error");
        }
    });

您还需要像这样将notifySuccess放置在RemoveHandler中:

microsoftTeams.settings.registerOnRemoveHandler(function (removeEvent) {
    var removeCalled = true;
    removeEvent.notifySuccess();
});

0 个答案:

没有答案