Closed ManuelTS closed 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.
@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.
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.
@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";
.
@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.
@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?
@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.
Closing issue for now. Please let me know if there is anything more I can help you out with.
Whenever I include:
in any file and i run
npm start
from anInteliJ/Run Configuration
for:I get:
Versions:
.babelrc.json
: