OfficeDev / microsoft-teams-library-js

JavaScript library for use by Microsoft Teams apps
https://docs.microsoft.com/microsoftteams/platform/
Other
434 stars 199 forks source link

ReferenceError: window is not defined with node.js 13.13.0 #367

Closed ManuelTS closed 4 years ago

ManuelTS commented 4 years ago

Whenever I include:

import * as mst from "@microsoft/teams-js";

in any file and i run npm startfrom an InteliJ/Run Configuration for:

{
  "name": "msteams-nodejs-hello-world",
  "version": "1.0.0",
  "description": "Microsoft Teams Hello World sample app written in ES6 with Bot Framework v4 SDK",
  "scripts": {
    "start": "nodemon --exec babel-node src/app.js",
    "build": "npm build",
    "clean": "rm -rf node_modules",
    "reinstall": "npm run clean && npm install",
    "rebuild": "npm run clean && npm install && npm run build"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/OfficeDev/msteams-samples-hello-world-nodejs.git"
  },
  "author": "Microsoft Corp.",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/OfficeDev/msteams-samples-hello-world-nodejs/issues"
  },
  "homepage": "https://docs.microsoft.com/en-us/microsoftteams/platform/get-started/get-started-nodejs",
  "dependencies": {
    "@babel/polyfill": "^7.8.7",
    "@microsoft/microsoft-graph-client": "^2.0.0",
    "@microsoft/teams-js": "^1.7.0",
    "axios": "^0.19.2",
    "botbuilder": "^4.8.0",
    "config": "^1.28.1",
    "core-js": "^2.6.11",
    "dotenv": "^8.2.0",
    "path": "^0.12.7",
    "restify": "^8.5.1",
    "send": "^0.17.1"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.9.6",
    "@babel/node": "^7.8.7",
    "@babel/preset-env": "^7.9.6",
    "@babel/register": "^7.9.0",
    "del": "^5.1.0",
    "gulp": "^4.0.2",
    "gulp-zip": "^5.0.1",
    "nodemon": "^2.0.3"
  }
}

I get:

/Users/manuel/.nvm/versions/node/v13.13.0/bin/node /Users/manuel/.nvm/versions/node/v13.13.0/lib/node_modules/npm/bin/npm-cli.js start
Debugger listening on ws://127.0.0.1:51653/0406c727-c9b1-4751-a1e0-fc0e7acc3a44
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

> msteams-nodejs-hello-world@1.0.0 start /Users/manuel/Desktop/projects/mst-claps/msteams-samples-hello-world-nodejs
> nodemon --exec babel-node src/app.js

Debugger listening on ws://127.0.0.1:51657/f5550d09-7418-41e4-98ee-47d8f15c11a8
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
[nodemon] 2.0.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node src/app.js`
Debugger listening on ws://127.0.0.1:51662/25544b06-f90e-4369-b6de-8aa8155f7319
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger listening on ws://127.0.0.1:51665/0a444c98-a3e2-46f1-83de-18e2e8b4605f
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
/Users/manuel/Desktop/projects/mst-claps/msteams-samples-hello-world-nodejs/node_modules/@microsoft/teams-js/dist/MicrosoftTeams.min.js:1
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("microsoftTeams",[],n):"object"==typeof exports?exports.microsoftTeams=n():e.microsoftTeams=n()}(window,function(){return function(e){var n={};function t(a){if(n[a])return n[a].exports;var r=n[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=n,t.d=function(e,n,a){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(a,r,function(n){return e[n]}.bind(null,r));return a},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=8)}([function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=function(){function e(){}return e.initializeCalled=!1,e.initializeCompleted=!1,e.additionalValidOrigins=[],e.additionalValidOriginsRegexp=null,e.initializeCallbacks=[],e.isFramelessWindow=!1,e.parentMessageQueue=[],e.childMessageQueue=[],e.nextMessageId=0,e.handlers={},e.callbacks={},e.printCapabilityEnabled=!1,e}();n.GlobalVars=a},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(4),r=t(3),i=t(0),s=t(2);function o(e,n){return(!i.GlobalVars.currentWindow||e!==i.GlobalVars.currentWindow)&&(!!(i.GlobalVars.currentWindow&&i.GlobalVars.currentWindow.location&&n&&n===i.GlobalVars.currentWindow.location.origin)||!!(r.validOriginRegExp.test(n.toLowerCase())||i.GlobalVars.additionalValidOriginsRegexp&&i.GlobalVars.additionalValidOriginsRegexp.test(n.toLowerCase())))}function l(e,n){!i.GlobalVars.parentWindow||i.GlobalVars.parentWindow.closed||e===i.GlobalVars.parentWindow?(i.GlobalVars.parentWindow=e,i.GlobalVars.parentOrigin=n):i.GlobalVars.childWindow&&!i.GlobalVars.childWindow.closed&&e!==i.GlobalVars.childWindow||(i.GlobalVars.childWindow=e,i.GlobalVars.childOrigin=n),i.GlobalVars.parentWindow&&i.GlobalVars.parentWindow.closed&&(i.GlobalVars.parentWindow=null,i.GlobalVars.parentOrigin=null),i.GlobalVars.childWindow&&i.GlobalVars.childWindow.closed&&(i.GlobalVars.childWindow=null,i.GlobalVars.childOrigin=null),g(i.GlobalVars.parentWindow),g(i.GlobalVars.childWindow)}function u(e){if("id"in e.data&&"number"==typeof e.data.id){var n=e.data,t=i.GlobalVars.callbacks[n.id];t&&(t.apply(null,n.args),delete i.GlobalVars.callbacks[n.id])}else if("func"in e.data&&"string"==typeof e.data.func){n=e.data;var a=i.GlobalVars.handlers[n.func];a&&a.apply(this,n.args)}}function c(e){if("id"in e.data&&"func"in e.data){var n=e.data,t=n.func?i.GlobalVars.handlers[n.func]:null;if(t){var a=t.apply(this,n.args);void 0!==a&&p(n.id,Array.isArray(a)?a:[a])}else{var r=b(n.func,n.args);i.GlobalVars.callbacks[r]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i.GlobalVars.childWindow&&p(n.id,e)}}}}function d(e){return e===i.GlobalVars.parentWindow?i.GlobalVars.parentMessageQueue:e===i.GlobalVars.childWindow?i.GlobalVars.childMessageQueue:[]}function f(e){return e===i.GlobalVars.parentWindow?i.GlobalVars.parentOrigin:e===i.GlobalVars.childWindow?i.GlobalVars.childOrigin:null}function g(e){for(var n=f(e),t=d(e);e&&n&&t.length>0;)e.postMessage(t.shift(),n)}function b(e,n){var t=i.GlobalVars.parentWindow,a=v(e,n);if(i.GlobalVars.isFramelessWindow)i.GlobalVars.currentWindow&&i.GlobalVars.currentWindow.nativeInterface&&i.GlobalVars.currentWindow.nativeInterface.framelessPostMessage(JSON.stringify(a));else{var r=f(t);t&&r?t.postMessage(a,r):d(t).push(a)}return a.id}function p(e,n){var t=i.GlobalVars.childWindow,a=V(e,n),r=f(t);t&&r&&t.postMessage(a,r)}function h(e,n){var t=i.GlobalVars.childWindow,a=G(e,n),r=f(t);t&&r?t.postMessage(a,r):d(t).push(a)}function v(e,n){return{id:i.GlobalVars.nextMessageId++,func:e,args:n||[]}}function V(e,n){return{id:e,args:n||[]}}function G(e,n){return{func:e,args:n||[]}}i.GlobalVars.handlers.themeChange=function(e){i.GlobalVars.themeChangeHandler&&i.GlobalVars.themeChangeHandler(e);i.GlobalVars.childWindow&&h("themeChange",[e])},i.GlobalVars.handlers.fullScreenChange=function(e){i.GlobalVars.fullScreenChangeHandler&&i.GlobalVars.fullScreenChangeHandler(e)},i.GlobalVars.handlers.backButtonPress=function(){i.GlobalVars.backButtonPressHandler&&i.GlobalVars.backButtonPressHandler()||a.navigateBack()},i.GlobalVars.handlers.load=function(e){i.GlobalVars.loadHandler&&i.GlobalVars.loadHandler(e);i.GlobalVars.childWindow&&h("load",[e])},i.GlobalVars.handlers.beforeUnload=function(){var e=function(){b("readyToUnload",[])};i.GlobalVars.beforeUnloadHandler&&i.GlobalVars.beforeUnloadHandler(e)||e()},i.GlobalVars.handlers.changeSettings=function(){i.GlobalVars.changeSettingsHandler&&i.GlobalVars.changeSettingsHandler()},i.GlobalVars.handlers.startConversation=function(e,n,t,a){i.GlobalVars.onStartConversationHandler&&i.GlobalVars.onStartConversationHandler({subEntityId:e,conversationId:n,channelId:t,entityId:a})},i.GlobalVars.handlers.closeConversation=function(e,n,t,a){i.GlobalVars.onCloseConversationHandler&&i.GlobalVars.onCloseConversationHandler({subEntityId:e,conversationId:n,channelId:t,entityId:a})},n.ensureInitialized=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(!i.GlobalVars.initializeCalled)throw new Error("The library has not yet been initialized");if(i.GlobalVars.frameContext&&e&&e.length>0){for(var t=!1,a=0;a<e.length;a++)if(e[a]===i.GlobalVars.frameContext){t=!0;break}if(!t)throw new Error("This call is not allowed in the '"+i.GlobalVars.frameContext+"' context")}},n.isAPISupportedByPlatform=function(e){void 0===e&&(e=r.defaultSDKVersionForCompatCheck);var n=s.compareSDKVersions(i.GlobalVars.clientSupportedSDKVersion,e);return!isNaN(n)&&n>=0},n.processMessage=function(e){if(e&&e.data&&"object"==typeof e.data){var n=e.source||e.originalEvent&&e.originalEvent.source,t=e.origin||e.originalEvent&&e.originalEvent.origin;o(n,t)&&(l(n,t),n===i.GlobalVars.parentWindow?u(e):n===i.GlobalVars.childWindow&&c(e))}},n.handleParentMessage=u,n.processAdditionalValidOrigins=function(e){var n=i.GlobalVars.additionalValidOrigins.concat(e.filter(function(e){return"string"==typeof e&&r.userOriginUrlValidationRegExp.test(e)})),t={};n=n.filter(function(e){return!t[e]&&(t[e]=!0,!0)}),i.GlobalVars.additionalValidOrigins=n,i.GlobalVars.additionalValidOrigins.length>0?i.GlobalVars.additionalValidOriginsRegexp=s.generateRegExpFromUrls(i.GlobalVars.additionalValidOrigins):i.GlobalVars.additionalValidOriginsRegexp=null},n.waitForMessageQueue=function(e,n){var t=i.GlobalVars.currentWindow.setInterval(function(){0===d(e).length&&(clearInterval(t),n())},100)},n.sendMessageRequestToParent=b,n.sendMessageEventToChild=h},function(e,n,t){"use strict";function a(e){for(var n="^",t=e.split("."),a=0;a<t.length;a++)n+=(a>0?"[.]":"")+t[a].replace("*","[^/^.]+");return n+="$"}Object.defineProperty(n,"__esModule",{value:!0}),n.generateRegExpFromUrls=function(e){for(var n="",t=0;t<e.length;t++)n+=(0===t?"":"|")+a(e[t]);return new RegExp(n)},n.getGenericOnCompleteHandler=function(e){return function(n,t){if(!n)throw new Error(e||t)}},n.compareSDKVersions=function(e,n){if("string"!=typeof e||"string"!=typeof n)return NaN;var t=e.split("."),a=n.split(".");function r(e){return/^\d+$/.test(e)}if(!t.every(r)||!a.every(r))return NaN;for(;t.length<a.length;)t.push("0");for(;a.length<t.length;)a.push("0");for(var i=0;i<t.length;++i)if(t[i]!=a[i])return t[i]>a[i]?1:-1;return 0}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(2);n.version="1.7.0",n.defaultSDKVersionForCompatCheck="1.6.0",n.validOrigins=["https://teams.microsoft.com","https://teams.microsoft.us","https://gov.teams.microsoft.us","https://dod.teams.microsoft.us","https://int.teams.microsoft.com","https://devspaces.skype.com","https://ssauth.skype.com","https://local.teams.office.com","https://local.teams.office.com:8080","https://msft.spoppe.com","https://*.sharepoint.com","https://*.sharepoint-df.com","https://*.sharepointonline.com","https://outlook.office.com","https://outlook-sdf.office.com","https://*.teams.microsoft.com","https://www.office.com","https://word.office.com","https://excel.office.com","https://powerpoint.office.com","https://www.officeppe.com","https://*.www.office.com","http://127.0.0.1:5000"],n.validOriginRegExp=a.generateRegExpFromUrls(n.validOrigins),n.userOriginUrlValidationRegExp=/^https\:\/\//},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0),i=t(3),s=t(5),o=t(2),l=t(6);function u(e,n){if(!r.GlobalVars.initializeCalled){r.GlobalVars.initializeCalled=!0;var t=function(e){return a.processMessage(e)};r.GlobalVars.currentWindow=r.GlobalVars.currentWindow||window,r.GlobalVars.parentWindow=r.GlobalVars.currentWindow.parent!==r.GlobalVars.currentWindow.self?r.GlobalVars.currentWindow.parent:r.GlobalVars.currentWindow.opener,r.GlobalVars.parentWindow?r.GlobalVars.currentWindow.addEventListener("message",t,!1):(r.GlobalVars.isFramelessWindow=!0,window.onNativeMessage=a.handleParentMessage);try{r.GlobalVars.parentOrigin="*";var o=a.sendMessageRequestToParent("initialize",[i.version]);r.GlobalVars.callbacks[o]=function(e,n,t){void 0===t&&(t=i.defaultSDKVersionForCompatCheck),r.GlobalVars.frameContext=e,r.GlobalVars.hostClientType=n,r.GlobalVars.clientSupportedSDKVersion=t,r.GlobalVars.initializeCallbacks.forEach(function(e){return e()}),r.GlobalVars.initializeCallbacks=[],r.GlobalVars.initializeCompleted=!0}}finally{r.GlobalVars.parentOrigin=null}this._uninitialize=function(){r.GlobalVars.frameContext&&(d(null),f(null),g(null),p(null),b(null),l.logs.registerGetLogHandler(null)),"settings"===r.GlobalVars.frameContext&&s.settings.registerOnSaveHandler(null),"remove"===r.GlobalVars.frameContext&&s.settings.registerOnRemoveHandler(null),r.GlobalVars.isFramelessWindow||r.GlobalVars.currentWindow.removeEventListener("message",t,!1),r.GlobalVars.initializeCalled=!1,r.GlobalVars.initializeCompleted=!1,r.GlobalVars.initializeCallbacks=[],r.GlobalVars.additionalValidOrigins=[],r.GlobalVars.parentWindow=null,r.GlobalVars.parentOrigin=null,r.GlobalVars.parentMessageQueue=[],r.GlobalVars.childWindow=null,r.GlobalVars.childOrigin=null,r.GlobalVars.childMessageQueue=[],r.GlobalVars.nextMessageId=0,r.GlobalVars.callbacks={},r.GlobalVars.frameContext=null,r.GlobalVars.hostClientType=null,r.GlobalVars.isFramelessWindow=!1}}Array.isArray(n)&&a.processAdditionalValidOrigins(n),e&&(r.GlobalVars.initializeCompleted?e():r.GlobalVars.initializeCallbacks.push(e))}function c(){window.print()}function d(e){a.ensureInitialized(),r.GlobalVars.themeChangeHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["themeChange"])}function f(e){a.ensureInitialized(),r.GlobalVars.fullScreenChangeHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["fullScreen"])}function g(e){a.ensureInitialized(),r.GlobalVars.backButtonPressHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["backButton"])}function b(e){a.ensureInitialized(),r.GlobalVars.loadHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["load"])}function p(e){a.ensureInitialized(),r.GlobalVars.beforeUnloadHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["beforeUnload"])}function h(e){a.ensureInitialized("content"),a.sendMessageRequestToParent("setFrameContext",[e])}n.initialize=u,n._initialize=function(e){r.GlobalVars.currentWindow=e},n._uninitialize=function(){},n.enablePrintCapability=function(){r.GlobalVars.printCapabilityEnabled||(r.GlobalVars.printCapabilityEnabled=!0,a.ensureInitialized(),document.addEventListener("keydown",function(e){(e.ctrlKey||e.metaKey)&&80===e.keyCode&&(c(),e.cancelBubble=!0,e.preventDefault(),e.stopImmediatePropagation())}))},n.print=c,n.getContext=function(e){a.ensureInitialized();var n=a.sendMessageRequestToParent("getContext");r.GlobalVars.callbacks[n]=function(n){n.frameContext||(n.frameContext=r.GlobalVars.frameContext),e(n)}},n.registerOnThemeChangeHandler=d,n.registerFullScreenHandler=f,n.registerBackButtonHandler=g,n.navigateBack=function(e){a.ensureInitialized();var n=a.sendMessageRequestToParent("navigateBack",[]);r.GlobalVars.callbacks[n]=e||o.getGenericOnCompleteHandler("Back navigation is not supported in the current client or context.")},n.registerOnLoadHandler=b,n.registerBeforeUnloadHandler=p,n.registerChangeSettingsHandler=function(e){a.ensureInitialized("content"),r.GlobalVars.changeSettingsHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["changeSettings"])},n.navigateCrossDomain=function(e,n){a.ensureInitialized("content","sidePanel","settings","remove","task");var t=a.sendMessageRequestToParent("navigateCrossDomain",[e]);r.GlobalVars.callbacks[t]=n||o.getGenericOnCompleteHandler("Cross-origin navigation is only supported for URLs matching the pattern registered in the manifest.")},n.getTabInstances=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("getTabInstances",[n]);r.GlobalVars.callbacks[t]=e},n.getMruTabInstances=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("getMruTabInstances",[n]);r.GlobalVars.callbacks[t]=e},n.shareDeepLink=function(e){a.ensureInitialized("content","sidePanel"),a.sendMessageRequestToParent("shareDeepLink",[e.subEntityId,e.subEntityLabel,e.subEntityWebUrl])},n.executeDeepLink=function(e,n){a.ensureInitialized("content","sidePanel","task");var t=a.sendMessageRequestToParent("executeDeepLink",[e]);r.GlobalVars.callbacks[t]=n||o.getGenericOnCompleteHandler()},n.navigateToTab=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("navigateToTab",[e]);r.GlobalVars.callbacks[t]=n||o.getGenericOnCompleteHandler("Invalid internalTabInstanceId and/or channelId were/was provided")},n.setFrameContext=h,n.initializeWithFrameContext=function(e,n,t){u(n,t),h(e)}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0),i=t(2);!function(e){var n,t;r.GlobalVars.handlers["settings.save"]=function(e){var t=new s(e);n?n(t):t.notifySuccess()},r.GlobalVars.handlers["settings.remove"]=function(){var e=new o;t?t(e):e.notifySuccess()},e.setValidityState=function(e){a.ensureInitialized("settings","remove"),a.sendMessageRequestToParent("settings.setValidityState",[e])},e.getSettings=function(e){a.ensureInitialized("content","settings","remove");var n=a.sendMessageRequestToParent("settings.getSettings");r.GlobalVars.callbacks[n]=e},e.setSettings=function(e,n){a.ensureInitialized("content","settings");var t=a.sendMessageRequestToParent("settings.setSettings",[e]);r.GlobalVars.callbacks[t]=n||i.getGenericOnCompleteHandler()},e.registerOnSaveHandler=function(e){a.ensureInitialized("settings"),n=e,e&&a.sendMessageRequestToParent("registerHandler",["save"])},e.registerOnRemoveHandler=function(e){a.ensureInitialized("remove"),t=e,e&&a.sendMessageRequestToParent("registerHandler",["remove"])};var s=function(){function e(e){this.notified=!1,this.result=e||{}}return e.prototype.notifySuccess=function(){this.ensureNotNotified(),a.sendMessageRequestToParent("settings.save.success"),this.notified=!0},e.prototype.notifyFailure=function(e){this.ensureNotNotified(),a.sendMessageRequestToParent("settings.save.failure",[e]),this.notified=!0},e.prototype.ensureNotNotified=function(){if(this.notified)throw new Error("The SaveEvent may only notify success or failure once.")},e}();var o=function(){function e(){this.notified=!1}return e.prototype.notifySuccess=function(){this.ensureNotNotified(),a.sendMessageRequestToParent("settings.remove.success"),this.notified=!0},e.prototype.notifyFailure=function(e){this.ensureNotNotified(),a.sendMessageRequestToParent("settings.remove.failure",[e]),this.notified=!0},e.prototype.ensureNotNotified=function(){if(this.notified)throw new Error("The removeEvent may only notify success or failure once.")},e}()}(n.settings||(n.settings={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0);!function(e){r.GlobalVars.handlers["log.request"]=function(){if(r.GlobalVars.getLogHandler){var e=r.GlobalVars.getLogHandler();a.sendMessageRequestToParent("log.receive",[e])}},e.registerGetLogHandler=function(e){a.ensureInitialized(),r.GlobalVars.getLogHandler=e,e&&a.sendMessageRequestToParent("registerHandler",["log.request"])}}(n.logs||(n.logs={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0),i=t(2),s=function(){function e(){}return e.prototype.postMessage=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("messageForChild",[e]);r.GlobalVars.callbacks[t]=n||i.getGenericOnCompleteHandler()},e.prototype.addEventListener=function(e,n){"message"===e&&(r.GlobalVars.handlers.messageForParent=n)},e}();n.ChildAppWindow=s;var o=function(){function e(){}return Object.defineProperty(e,"Instance",{get:function(){return this._instance||(this._instance=new this)},enumerable:!0,configurable:!0}),e.prototype.postMessage=function(e,n){a.ensureInitialized("task");var t=a.sendMessageRequestToParent("messageForParent",[e]);r.GlobalVars.callbacks[t]=n||i.getGenericOnCompleteHandler()},e.prototype.addEventListener=function(e,n){"message"===e&&(r.GlobalVars.handlers.messageForChild=n)},e}();n.ParentAppWindow=o},function(e,n,t){"use strict";function a(e){for(var t in e)n.hasOwnProperty(t)||(n[t]=e[t])}Object.defineProperty(n,"__esModule",{value:!0}),a(t(9)),a(t(14))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(10);n.bot=a.bot;var r=t(11);n.menus=r.menus;var i=t(6);n.logs=i.logs;var s=t(12);n.enterFullscreen=s.enterFullscreen,n.exitFullscreen=s.exitFullscreen,n.getChatMembers=s.getChatMembers,n.getConfigSetting=s.getConfigSetting,n.getUserJoinedTeams=s.getUserJoinedTeams,n.openFilePreview=s.openFilePreview,n.sendCustomMessage=s.sendCustomMessage,n.showNotification=s.showNotification,n.sendCustomEvent=s.sendCustomEvent,n.registerCustomHandler=s.registerCustomHandler,n.uploadCustomApp=s.uploadCustomApp;var o=t(13);n.conversations=o.conversations},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(0),r=t(1);!function(e){e.sendQuery=function(e,n,t){r.ensureInitialized();var i=r.sendMessageRequestToParent("bot.executeQuery",[e]);a.GlobalVars.callbacks[i]=function(e,a){e?n(a):t(a)}},e.getSupportedCommands=function(e,n){r.ensureInitialized();var t=r.sendMessageRequestToParent("bot.getSupportedCommands");a.GlobalVars.callbacks[t]=function(t,a){t?e(a):n(a)}},e.authenticate=function(e,n,t){r.ensureInitialized();var i=r.sendMessageRequestToParent("bot.authenticate",[e]);a.GlobalVars.callbacks[i]=function(e,a){e?n(a):t(a)}},function(e){e.Results="Results",e.Auth="Auth"}(e.ResponseType||(e.ResponseType={}))}(n.bot||(n.bot={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0);!function(e){var n,t,i,s=function(){return function(){this.enabled=!0}}();e.MenuItem=s,function(e){e.dropDown="dropDown",e.popOver="popOver"}(e.MenuListType||(e.MenuListType={})),r.GlobalVars.handlers.navBarMenuItemPress=function(e){n&&n(e)||(a.ensureInitialized(),a.sendMessageRequestToParent("handleNavBarMenuItemPress",[e]))},r.GlobalVars.handlers.actionMenuItemPress=function(e){t&&t(e)||(a.ensureInitialized(),a.sendMessageRequestToParent("handleActionMenuItemPress",[e]))},r.GlobalVars.handlers.setModuleView=function(e){i&&i(e)||(a.ensureInitialized(),a.sendMessageRequestToParent("viewConfigItemPress",[e]))},e.setUpViews=function(e,n){a.ensureInitialized(),i=n,a.sendMessageRequestToParent("setUpViews",[e])},e.setNavBarMenu=function(e,t){a.ensureInitialized(),n=t,a.sendMessageRequestToParent("setNavBarMenu",[e])},e.showActionMenu=function(e,n){a.ensureInitialized(),t=n,a.sendMessageRequestToParent("showActionMenu",[e])}}(n.menus||(n.menus={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0),i=t(2);n.getUserJoinedTeams=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("getUserJoinedTeams",[n]);r.GlobalVars.callbacks[t]=e},n.enterFullscreen=function(){a.ensureInitialized("content"),a.sendMessageRequestToParent("enterFullscreen",[])},n.exitFullscreen=function(){a.ensureInitialized("content"),a.sendMessageRequestToParent("exitFullscreen",[])},n.openFilePreview=function(e){a.ensureInitialized("content");var n=[e.entityId,e.title,e.description,e.type,e.objectUrl,e.downloadUrl,e.webPreviewUrl,e.webEditUrl,e.baseUrl,e.editFile,e.subEntityId];a.sendMessageRequestToParent("openFilePreview",n)},n.showNotification=function(e){a.ensureInitialized("content");var n=[e.message,e.notificationType];a.sendMessageRequestToParent("showNotification",n)},n.uploadCustomApp=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("uploadCustomApp",[e]);r.GlobalVars.callbacks[t]=n||i.getGenericOnCompleteHandler()},n.sendCustomMessage=function(e,n,t){a.ensureInitialized();var i=a.sendMessageRequestToParent(e,n);return"function"==typeof t&&(r.GlobalVars.callbacks[i]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];t.apply(null,e)}),i},n.sendCustomEvent=function(e,n){if(a.ensureInitialized(),!r.GlobalVars.childWindow)throw new Error("The child window has not yet been initialized or is not present");a.sendMessageEventToChild(e,n)},n.registerCustomHandler=function(e,n){var t=this;a.ensureInitialized(),r.GlobalVars.handlers[e]=function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];return n.apply(t,e)}},n.getChatMembers=function(e){a.ensureInitialized();var n=a.sendMessageRequestToParent("getChatMembers");r.GlobalVars.callbacks[n]=e},n.getConfigSetting=function(e,n){a.ensureInitialized();var t=a.sendMessageRequestToParent("getConfigSetting",[n]);r.GlobalVars.callbacks[t]=e}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0);!function(e){e.openConversation=function(e){a.ensureInitialized("content");var n=a.sendMessageRequestToParent("conversations.openConversation",[{title:e.title,subEntityId:e.subEntityId,conversationId:e.conversationId,channelId:e.channelId,entityId:e.entityId}]);r.GlobalVars.onCloseConversationHandler=e.onCloseConversation,r.GlobalVars.onStartConversationHandler=e.onStartConversation,r.GlobalVars.callbacks[n]=function(e,n){if(!e)throw new Error(n)}},e.closeConversation=function(){a.ensureInitialized("content"),a.sendMessageRequestToParent("conversations.closeConversation"),r.GlobalVars.onCloseConversationHandler=null,r.GlobalVars.onStartConversationHandler=null}}(n.conversations||(n.conversations={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(15);n.appInitialization=a.appInitialization;var r=t(16);n.authentication=r.authentication;var i=t(4);n.enablePrintCapability=i.enablePrintCapability,n.executeDeepLink=i.executeDeepLink,n.getContext=i.getContext,n.getMruTabInstances=i.getMruTabInstances,n.getTabInstances=i.getTabInstances,n.initialize=i.initialize,n.initializeWithFrameContext=i.initializeWithFrameContext,n.navigateBack=i.navigateBack,n.navigateCrossDomain=i.navigateCrossDomain,n.navigateToTab=i.navigateToTab,n.print=i.print,n.registerBackButtonHandler=i.registerBackButtonHandler,n.registerBeforeUnloadHandler=i.registerBeforeUnloadHandler,n.registerChangeSettingsHandler=i.registerChangeSettingsHandler,n.registerFullScreenHandler=i.registerFullScreenHandler,n.registerOnLoadHandler=i.registerOnLoadHandler,n.registerOnThemeChangeHandler=i.registerOnThemeChangeHandler,n.setFrameContext=i.setFrameContext,n.shareDeepLink=i.shareDeepLink;var s=t(5);n.settings=s.settings;var o=t(17);n.tasks=o.tasks;var l=t(7);n.ChildAppWindow=l.ChildAppWindow,n.ParentAppWindow=l.ParentAppWindow;var u=t(18);n.captureImage=u.captureImage,n.FileFormat=u.FileFormat},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(3);!function(e){e.notifyAppLoaded=function(){a.ensureInitialized(),a.sendMessageRequestToParent("appInitialization.appLoaded",[r.version])},e.notifySuccess=function(){a.ensureInitialized(),a.sendMessageRequestToParent("appInitialization.success",[r.version])},e.notifyFailure=function(e){a.ensureInitialized(),a.sendMessageRequestToParent("appInitialization.failure",[e.reason,e.message])}}(n.appInitialization||(n.appInitialization={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),r=t(0);!function(e){var n,t;function i(){o();try{r.GlobalVars.childWindow&&r.GlobalVars.childWindow.close()}finally{r.GlobalVars.childWindow=null,r.GlobalVars.childOrigin=null}}function s(e){n=e,i();var t=n.width||600,a=n.height||400;t=Math.min(t,r.GlobalVars.currentWindow.outerWidth-400),a=Math.min(a,r.GlobalVars.currentWindow.outerHeight-200);var s=document.createElement("a");s.href=n.url;var o=void 0!==r.GlobalVars.currentWindow.screenLeft?r.GlobalVars.currentWindow.screenLeft:r.GlobalVars.currentWindow.screenX,c=void 0!==r.GlobalVars.currentWindow.screenTop?r.GlobalVars.currentWindow.screenTop:r.GlobalVars.currentWindow.screenY;o+=r.GlobalVars.currentWindow.outerWidth/2-t/2,c+=r.GlobalVars.currentWindow.outerHeight/2-a/2,r.GlobalVars.childWindow=r.GlobalVars.currentWindow.open(s.href,"_blank","toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, top="+c+", left="+o+", width="+t+", height="+a),r.GlobalVars.childWindow?l():u("FailedToOpenWindow")}function o(){t&&(clearInterval(t),t=0),delete r.GlobalVars.handlers.initialize,delete r.GlobalVars.handlers.navigateCrossDomain}function l(){o(),t=r.GlobalVars.currentWindow.setInterval(function(){if(!r.GlobalVars.childWindow||r.GlobalVars.childWindow.closed)u("CancelledByUser");else{var e=r.GlobalVars.childOrigin;try{r.GlobalVars.childOrigin="*",a.sendMessageEventToChild("ping")}finally{r.GlobalVars.childOrigin=e}}},100),r.GlobalVars.handlers.initialize=function(){return["authentication",r.GlobalVars.hostClientType]},r.GlobalVars.handlers.navigateCrossDomain=function(){return!1}}function u(e){try{n&&n.failureCallback&&n.failureCallback(e)}finally{n=null,i()}}function c(e,n,t){if(e){var a=document.createElement("a");a.href=decodeURIComponent(e),a.host&&a.host!==window.location.host&&"outlook.office.com"===a.host&&a.search.indexOf("client_type=Win32_Outlook")>-1&&(n&&"result"===n&&(t&&(a.href=d(a.href,"result",t)),r.GlobalVars.currentWindow.location.assign(d(a.href,"authSuccess",""))),n&&"reason"===n&&(t&&(a.href=d(a.href,"reason",t)),r.GlobalVars.currentWindow.location.assign(d(a.href,"authFailure",""))))}}function d(e,n,t){var a=e.indexOf("#"),r=-1===a?"#":e.substr(a);return r=r+"&"+n+(""!==t?"="+t:""),(e=-1===a?e:e.substr(0,a))+r}r.GlobalVars.handlers["authentication.authenticate.success"]=function(e){try{n&&n.successCallback&&n.successCallback(e)}finally{n=null,i()}},r.GlobalVars.handlers["authentication.authenticate.failure"]=u,e.registerAuthenticationHandlers=function(e){n=e},e.authenticate=function(e){var t=void 0!==e?e:n;if(a.ensureInitialized("content","sidePanel","settings","remove","task"),"desktop"===r.GlobalVars.hostClientType||"android"===r.GlobalVars.hostClientType||"ios"===r.GlobalVars.hostClientType||"rigel"===r.GlobalVars.hostClientType){var i=document.createElement("a");i.href=t.url;var o=a.sendMessageRequestToParent("authentication.authenticate",[i.href,t.width,t.height]);r.GlobalVars.callbacks[o]=function(e,n){e?t.successCallback(n):t.failureCallback(n)}}else s(t)},e.getAuthToken=function(e){a.ensureInitialized();var n=a.sendMessageRequestToParent("authentication.getAuthToken",[e.resources,e.claims,e.silent]);r.GlobalVars.callbacks[n]=function(n,t){n?e.successCallback(t):e.failureCallback(t)}},e.getUser=function(e){a.ensureInitialized();var n=a.sendMessageRequestToParent("authentication.getUser");r.GlobalVars.callbacks[n]=function(n,t){n?e.successCallback(t):e.failureCallback(t)}},e.notifySuccess=function(e,n){c(n,"result",e),a.ensureInitialized("authentication"),a.sendMessageRequestToParent("authentication.authenticate.success",[e]),a.waitForMessageQueue(r.GlobalVars.parentWindow,function(){return setTimeout(function(){return r.GlobalVars.currentWindow.close()},200)})},e.notifyFailure=function(e,n){c(n,"reason",e),a.ensureInitialized("authentication"),a.sendMessageRequestToParent("authentication.authenticate.failure",[e]),a.waitForMessageQueue(r.GlobalVars.parentWindow,function(){return setTimeout(function(){return r.GlobalVars.currentWindow.close()},200)})}}(n.authentication||(n.authentication={}))},function(e,n,t){"use strict";var a=this&&this.__rest||function(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(a=Object.getOwnPropertySymbols(e);r<a.length;r++)n.indexOf(a[r])<0&&(t[a[r]]=e[a[r]])}return t};Object.defineProperty(n,"__esModule",{value:!0});var r=t(1),i=t(0),s=t(7);!function(e){e.startTask=function(e,n){r.ensureInitialized("content","sidePanel");var t=r.sendMessageRequestToParent("tasks.startTask",[e]);return i.GlobalVars.callbacks[t]=n,new s.ChildAppWindow},e.updateTask=function(e){r.ensureInitialized("content","sidePanel","task"),e.width,e.height;var n=a(e,["width","height"]);if(Object.keys(n).length)throw new Error("updateTask requires a taskInfo argument containing only width and height");r.sendMessageRequestToParent("tasks.updateTask",[e])},e.submitTask=function(e,n){r.ensureInitialized("content","sidePanel","task"),r.sendMessageRequestToParent("tasks.completeTask",[e,Array.isArray(n)?n:[n]])}}(n.tasks||(n.tasks={}))},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var a=t(0),r=t(1),i="1.7.0";!function(e){e.Base64="base64"}(n.FileFormat||(n.FileFormat={})),n.captureImage=function(e){if(!e)throw new Error("[captureImage] Callback cannot be null");if(r.ensureInitialized("content","task"),a.GlobalVars.isFramelessWindow)if(r.isAPISupportedByPlatform(i)){var n=r.sendMessageRequestToParent("captureImage");a.GlobalVars.callbacks[n]=e}else e({errorCode:9e3},void 0);else e({errorCode:100},void 0)}}])});
                                                                                                                                                                                                                                  ^

ReferenceError: window is not defined
    at Object.<anonymous> (/Users/manuel/Desktop/projects/mst-claps/msteams-samples-hello-world-nodejs/node_modules/@microsoft/teams-js/dist/MicrosoftTeams.min.js:1:227)
    at Module._compile (internal/modules/cjs/loader.js:1123:30)
    at Module._compile (/Users/manuel/Desktop/projects/mst-claps/msteams-samples-hello-world-nodejs/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Object.newLoader [as .js] (/Users/manuel/Desktop/projects/mst-claps/msteams-samples-hello-world-nodejs/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:972:32)
    at Function.Module._load (internal/modules/cjs/loader.js:872:14)
    at Module.require (internal/modules/cjs/loader.js:1012:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/manuel/Desktop/projects/mst-claps/msteams-samples-hello-world-nodejs/src/dialog.js:1:1)
Waiting for the debugger to disconnect...
[nodemon] app crashed - waiting for file changes before starting...

Versions:

Manuels-MBP:msteams-samples-hello-world-nodejs manuel$ nvm --version
0.35.3
Manuels-MBP:msteams-samples-hello-world-nodejs manuel$ npm -v
6.14.4
Manuels-MBP:msteams-samples-hello-world-nodejs manuel$ node -v
v13.13.0

.babelrc.json:

{
  "presets": [
    [
      "@babel/env",
      {
        "targets": {
          "edge": "17",
          "firefox": "60",
          "chrome": "67",
          "safari": "11.1",
        },
        "useBuiltIns": "usage",
        "corejs": "2.6.11"
      }
    ]
  ]
}
ydogandjiev commented 4 years ago

@ManuelTS, it seems like you are trying to call our Client SDK from your Node.js service which typically runs on the server and doesn't have access to constructs like the window object. This SDK is meant to be used in the web app/page that runs in the user's browser or Teams Mobile/Desktop client.

ManuelTS commented 4 years ago

@ydogandjiev that is true, yes. I did not find the information in the docs - thank you for your reply! But with what SDK or API do I fetch information from the graph API in node.js? I mean in an offical tutorial, here:

var graph = require('@microsoft/microsoft-graph-client');
require('isomorphic-fetch');

module.exports = {
  getUserDetails: async function(accessToken) {
    const client = getAuthenticatedClient(accessToken);

    const user = await client.api('/me').get();
    return user;
  }
};

function getAuthenticatedClient(accessToken) {
  // Initialize Graph client
  const client = graph.Client.init({
    // Use the provided access token to authenticate
    // requests
    authProvider: (done) => {
      done(null, accessToken);
    }
  });

  return client;
}

they do the same. And with that error, I cannot even create a simple TaskModule with tasks.startTask.

ydogandjiev commented 4 years ago

The tutorial you pointed to actually shows you how to call the Graph API from your backend service: https://docs.microsoft.com/en-us/graph/tutorials/node?tutorial-step=3#get-user-details

You can read more about the available Teams APIs in the Graph: https://docs.microsoft.com/en-us/graph/api/resources/teams-api-overview?view=graph-rest-1.0

Just replace the /me with whatever Graph API endpoint you're looking to call.

ManuelTS commented 4 years ago

@ydogandjiev thanks for your support! I know, the code giving me problems on the import * as mst from "@microsoft/teams-js";, as said in my first post, is:

import * as mst from "@microsoft/teams-js";

export default class Dialog {
    constructor(){

    let taskInfo = {
        title: 'Example Title',
        height: 520,
        width: 430,
        url: 'https://www.example.com'
    };

    let submitHandler = (err, result) => {
        console.log(`Submit handler - err: ${err}`);
        console.log(`Submit handler - result\rName: ${result}\rEmail: ${result}\rFavorite book: ${result}`);
    };
    mst.tasks.startTask(taskInfo, submitHandler); // https://docs.microsoft.com/en-us/javascript/api/@microsoft/teams-js/microsoftteams.tasks?view=msteams-client-js-latest#starttask-taskinfo---err--string--result--string-----void-
    }
}

I want to display in a Dialog (TaskModule) a list where the user can select multiple team members. But I cannot even start a dialog pointing to the example URL first and adapt it later to the team member selection, since the compilation fails on import * as mst from "@microsoft/teams-js";.

ydogandjiev commented 4 years ago

@ManuelTS, if you are following the msteams-samples-hello-world-nodejs sample app then the only place where you can put your startTask call is in the static scripts (teamsapp.js) or the views (configure.html, first.html, etc.). You cannot use the Teams Client SDK in any of the other files since those actually run server-side.

ManuelTS commented 4 years ago

@ydogandjiev okay thank you very much for the clarification. To be on the safe side, hopefully my last question: To display all team members in a simple dialog invoked from mentioning my app with an @, I have to set the dialog content to a static .html wherein the the client SDK is running?

/Edit: After some further research, I have to user adaptive cards somehow in or to show a dialog, right?

ydogandjiev commented 4 years ago

@ManuelTS, I would recommend looking at Messaging Extensions: https://docs.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/what-are-messaging-extensions

That would allow you to bring up a dialog rendered via an adaptive card or hosted html page in response to the user @mentioning your app.

ydogandjiev commented 4 years ago

Closing issue for now. Please let me know if there is anything more I can help you out with.