Digital Assistant and Mobile

Get Involved. Join the Conversation.

Topic

    Pawan Gupta
    Microsoft Teams to ODA (how to pass username)Answered
    Topic posted November 6, 2019 by Pawan GuptaBlue Ribbon: 750+ Points, tagged Conversational AI, Virtual Assistant, VPA 
    36 Views, 8 Comments
    Title:
    Microsoft Teams to ODA (how to pass username)
    Summary:
    Microsoft Teams to ODA (how to pass username)
    Content:

    In enterprise digital assistant use case, MS Teams is going to be the blockbuster channel for accessing the digital assistants. I am trying to enable the DAs in MS team though need some help in documentation or any blog, article on how can we pass user details from MS Teams to ODA. Appreciate your help.

    Best Comment

    Rohit Dhamija

    Is client_id and client_secret same which we get while registering bot channel in azure?

    >>

     client_id=<Microsoft application Id>  \
     ‘client_secret=<Microsoft application pwd>' \

    Also could you help me with syntax how to get conversation id, is it somethign we can see somewhere in ODA page?

    >>    const userID = conversation.payload().userId;
        conversation.logger().info("conversation user ID = "+ userID);  

    In coversation.payload will give you JSON, from there you can extract the conversation ID

     

    Steps to generate the token: 
     
    curl -X POST \
      -F grant_type=client_credentials \
      -F client_id=<Microsoft application Id>  \
      -F ‘client_secret=<Microsfot application pwd>' \
     
    Note:
    <Microsoft application Id> : application id  copied from micro soft Bots channel registration process. ( the same thing used to create micro soft channel in ODA platform)
    <Microsfot application pwd>: pass word copied from micro soft Bots channel registration process. ( the same thing used to create micro soft channel in ODA platform)
     
    Api to get email id
     
    curl -X GET \
      -H 'Authorization: Bearer <token>’ 
     
    Note:
    <conversationId>     : a:1d7E-p-PdUrxcrATxdcgIeynUKLwWQv4kx7DRQyek4l1noc6JIMp4A4iyhj2Dfhuax6zZx0ymsoYYsLpUs95YCATiz6pH8e5-V8r62FfjTigPfiLw3YVIOqox1pM-IFeO
    <authToken>         : Generate by above curl command. 

    Comment

     

    • Rohit Dhamija

      Hi Pawan,

      MS Teams as well as other channels like Slack don't have the same mechanism as the Web SDKs because the user is already identified in the system.

      The approach used for these channels is to call the provider profile resolver and get the user information from there.

      So you can create a simple custom component to access the user name.

      1. Fetch the conversation object and get the conversation ID

      2. Make GET request to https://smba.trafficmanager.net/in/v3/conversations/' + convID+ '/members' to obtain profile information

      Thanks and Regards,

      Rohit Dhamija

       
    • Pawan Gupta
      Thanks what Authentication you passed in the postman, is it oda user/password?
    • Rohit Dhamija

      1. You need to make call to https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token to obtain the token. Here is the code snippet for reference purpose only:

            try {
                  let  jsonInput = {
                      "grant_type": "client_credentials",
                      "client_id": "YOUR_CLIENT_ID",
                      "client_secret": "YOUR_CLIENT_SECRET",
                      "scope": "https://api.botframework.com/.default"
                  }
                  let options = {
                      url: "https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token",
                      method: 'POST',
                      headers: {
                          'Content-Type': 'application/json'
                      },
                      formData: jsonInput
                     
                  };
                  let data = await request(options);
                  return JSON.parse(data.body);
              } catch (error) {
                  throw new Error(error);
              }

      2. Then, you will use this token to fetch profile information, here is the code for reference purpose only

          try {
                  let options = {
                      url: "https://smba.trafficmanager.net/in/v3/conversations/"+conversationId+"/members",
                      method: 'GET',
                      headers: {
                          'Content-Type': 'application/json',
                          'Authorization': 'Bearer '+token
                      }
                  };
                  let data = await request(options);
                  return JSON.parse(data.body);
              } catch (error) {
                  throw new Error(error);
              }

       

      Hope this helps!

       

    • Pawan Gupta

      Thanks Rohit, is client_id and client_secret same which we get while registering bot channel in azure?

          "client_id": "YOUR_CLIENT_ID",
                      "client_secret": "YOUR_CLIENT_SECRET",

    • Pawan Gupta

      Also could you help me with syntax how to get conversation id, is it somethign we can see somewhere in ODA page?

    • Rohit Dhamija

      Is client_id and client_secret same which we get while registering bot channel in azure?

      >>

       client_id=<Microsoft application Id>  \
       ‘client_secret=<Microsoft application pwd>' \

      Also could you help me with syntax how to get conversation id, is it somethign we can see somewhere in ODA page?

      >>    const userID = conversation.payload().userId;
          conversation.logger().info("conversation user ID = "+ userID);  

      In coversation.payload will give you JSON, from there you can extract the conversation ID

       

      Steps to generate the token: 
       
      curl -X POST \
        -F grant_type=client_credentials \
        -F client_id=<Microsoft application Id>  \
        -F ‘client_secret=<Microsfot application pwd>' \
       
      Note:
      <Microsoft application Id> : application id  copied from micro soft Bots channel registration process. ( the same thing used to create micro soft channel in ODA platform)
      <Microsfot application pwd>: pass word copied from micro soft Bots channel registration process. ( the same thing used to create micro soft channel in ODA platform)
       
      Api to get email id
       
      curl -X GET \
        -H 'Authorization: Bearer <token>’ 
       
      Note:
      <conversationId>     : a:1d7E-p-PdUrxcrATxdcgIeynUKLwWQv4kx7DRQyek4l1noc6JIMp4A4iyhj2Dfhuax6zZx0ymsoYYsLpUs95YCATiz6pH8e5-V8r62FfjTigPfiLw3YVIOqox1pM-IFeO
      <authToken>         : Generate by above curl command. 
    • Rohit Dhamija

      Hi Vikhil,

      Here is the POC to get conversationID in MS Teams

      1. Use below custom code

      'use strict';
       
      module.exports = {
        metadata: () => ({
          name: 'msteams.convid',
        }),
        invoke: (conversation, done) => {
          let email = conversation.payload()["userProfile"] ? conversation.payload().userProfile.userProfileDetails[0].email : "rohit.dhamija@gmail.com";
          let name = conversation.payload().from.name;
          let conversationId = conversation.payload().conversation.id; 
          conversation.logger().info('email: '+ email);        
          conversation.logger().info('name: '+ name);  
          conversation.logger().info('conversationId: '+ conversationId);        
          conversation.reply('conversationId: ' + conversationId);
          done();
        }
      };

      ++++++++++

      2. Here is the sample bot BotML code

      states:
        findMSTeamsuserID:
          component: msteams.convid
          transitions:
            return: "done"

      3) Create MSTeams channel and route it through the skill

      4) Just type Hi in channel, you will get conversation ID as reply.  Also you can check conversation logs.