Microsoft Teams Connector 1.1 の例

始める前に

これらの例を実行するには、以下が必要です。

  • Microsoft Teams の作業インスタンス

  • Microsoft Teams インスタンスにアクセスするためのログイン情報

  • Microsoft Teams Connector 1.0 以降

  • Microsoft Teams インスタンスの 2 人のユーザー (1 人のチームオーナーと 1 人のユーザー)

  • Anypoint Studio 7.x

OAuth 認証を設定する

このコネクタでは、OAuth を使用して接続を保護するため、OAuth 項目値 (クライアントログイン情報、キー、OAuth 関連の URL など) を指定する必要があります。次の手順を実行します。

  • OAuth 接続の設定ファイルを作成する

  • OAuth 関連のグローバル要素を設定する

  • プロパティファイルのグローバル要素を設定する

OAuth 接続の設定ファイルを作成する

[​Authorization Code​ (認証コード)] および [​Client Credentials​ (クライアントログイン情報)] 許可種別のプロパティが含まれる OAuth 接続の設定ファイルを作成します。

  1. /src/main/resources/​ フォルダー内に ​mule-app.properties​ という名前のファイルを作成します。

  2. mule-app.properties​ ファイルで、次のような [​Authorization Code​ (認証コード)] 許可種別の一連のプロパティを作成します。括弧で囲まれたテキスト (括弧を含む) は、各自の OAuth 設定の適切な値に置き換えます。

    config.oauth.authorization.code.consumerKey=<consumerKey>
    config.oauth.authorization.code.consumerSecret=<consumerSecret>
    config.oauth.authorization.code.authorizationUrl=<authorizationUrl>
    config.oauth.authorization.code.accessTokenUrl=<accessTokenUrl>
  3. mule-app.properties​ ファイルで、次のような [​Client Credentials​ (クライアントログイン情報)] 許可種別の一連のプロパティを作成します。括弧で囲まれたテキスト (括弧を含む) は、各自の OAuth 設定の適切な値に置き換えます。

    config.oauth.client.credentials.clientId=<clientId>
    config.oauth.client.credentials.clientSecret=<clientSecret>
    config.oauth.client.credentials.tokenUrl=<tokenUrl>

プロパティファイルの作成についての詳細は、​「プロパティプレースホルダーの設定」​を参照してください。

OAuth グローバル要素を設定する

OAuth_Authorization_Code_Config​ および ​OAuth_Client_Credentials_Config​ ファイルのグローバル要素を設定します。

  1. 新しい Mule プロジェクトを作成します。

  2. [Mule Palette (Mule パレット)]​ ビューで、​[Search in Exchange (Exchange 内を検索)]​ をクリックして「​microsoft teams​」と入力します。

  3. [Selected modules (選択したモジュール)]​ セクションに ​Microsoft Teams Connector​ を追加し、​[Finish (完了)]​ をクリックします。

  4. [Global Elements (グローバル要素)]​ タブをクリックし、​[Create (作成)]​ をクリックします。

  5. [Connector Configuration (コネクタ設定)] > [Microsoft Teams Authorization Code Config (Microsoft Teams 認証コード設定)]​ を選択し、​[OK]​ をクリックします。

  6. 次の値を入力します。

    項目 説明

    Name (名前)

    OAuth_Authorization_Code_Config

    設定の名前。

    Consumer key (コンシューマーキー)

    ${config.oauth.authorization.code.consumerKey}

    サービスプロバイダーに登録されている OAuth コンシューマーキー。

    Consumer secret (コンシューマーシークレット)

    ${config.oauth.authorization.code.consumerSecret}

    サービスプロバイダーに登録されている OAuth コンシューマーシークレット。

    Authorization url (認証 URL)

    ${config.oauth.authorization.code.authorizationUrl}

    サービスプロバイダーの認証エンドポイントの URL。

    Access token url (アクセストークン URL)

    ${config.oauth.authorization.code.accessTokenUrl}

    サービスプロバイダーのアクセストークンエンドポイントの URL。

    Scopes (スコープ)

    デフォルト (​https://graph.microsoft.com/.default​) のままにします。

    OAuth ダンス時に要求する Oauth スコープ。この値のデフォルトはアノテーションのスコープです。

    Listener config (リスナー設定)

    auth

    アクセストークンコールバックエンドポイントで要求をリスンする HTTP リスナー設定。

    Callback path (コールバックパス)

    /callback

    アクセストークンコールバックエンドポイントのパス。

    Authorize path (認証パス)

    authorizePath

    OAuth ダンスをトリガーするローカル HTTP エンドポイントのパス。

    External callback url (外部コールバック URL)

    http://localhost:8083/callback

    コールバックエンドポイントがプロキシの背後にあるか、間接 URL でアクセスする場合にコールバックエンドポイントにアクセスするために OAuth プロバイダーで使用する URL。

  7. [OK]​ をクリックします。

  8. [Global Elements (グローバル要素)]​ タブをクリックし、​[Create (作成)]​ をクリックします。

  9. [Connector Configuration (コネクタ設定)] > [Microsoft Teams Client Credentials Config (Microsoft Teams クライアントログイン情報設定)]​ を選択し、​[OK]​ をクリックします。

  10. 次の値を入力します。

    項目 説明

    Name (名前)

    Microsoft_Teams_Client_Credentials_Config

    設定の名前。

    Client id (クライアント ID)

    ${config.oauth.client.credentials.clientId}

    サービスプロバイダーに登録されている OAuth クライアント ID。

    Client secret (クライアントシークレット)

    ${config.oauth.client.credentials.clientSecret}

    サービスプロバイダーに登録されている OAuth クライアントシークレット。

    Token url (トークン URL)

    ${config.oauth.client.credentials.tokenUrl}

    サービスプロバイダーのトークンエンドポイントの URL。

    Scopes (スコープ)

    デフォルト (​https://graph.microsoft.com/.default​) のままにします。

    OAuth ダンス時に要求する Oauth スコープ。この値のデフォルトはアノテーションのスコープです。

  11. [OK]​ をクリックします。

プロパティファイルのグローバル要素を設定する

mule-app.properties​ ファイルのグローバル要素を設定し、このファイルの検索場所が Mule で認識されるようにします。

  1. [Global Elements (グローバル要素)]​ タブをクリックし、​[Create (作成)]​ をクリックします。

  2. [Choose Global Type (グローバル種別の選択)]​ ダイアログで、​[Configuration properties (設定プロパティ)]​ を選択し、​[OK]​ をクリックします。

  3. [File (ファイル)]​ 項目に「​mule.app.properties​」と入力します。

  4. [OK]​ をクリックします。

新しいチームを作成する

次のスクリーンショットは、新しいチームを作成する Studio アプリケーションフローを示しています。

新しいチームを作成するフロー
Figure 1. このようなフローを使用して、新しいチームを作成します。

新しいチームの作成には、HTTP ​Listener​ コンポーネント、​Transform Message​ コンポーネント、​Create Team​ 操作、2 番目の ​Transform Message​ コンポーネントの設定が含まれます。

フローを作成する手順は、次のとおりです。

  1. Studio で新しい Mule プロジェクトを作成します。

  2. [Mule Palette (Mule パレット)] ビューで​「HTTP」​を検索し、​[Listener]​ 操作を選択します。

  3. Listener​ 操作をキャンバスにドラッグします。

  4. Listener​ 設定で、​[Connector configuration (コネクタ設定)]​ 項目の横にある ​[+]​ をクリックしてグローバル要素を追加します。

  5. デフォルトを受け入れます。

  6. [HTTP] プロパティウィンドウで、​[Path (パス)]​ 項目を ​/createTeam​ に設定します。

最初の [Transform Message] コンポーネントを追加する

最初の ​Transform Message​ コンポーネントでは、チームの作成に使用する入力のテンプレートを作成します。

  1. [Mule Palette (Mule パレット)] ビューで、​「transform message」​を検索します。

  2. Transform Message​ コンポーネントをキャンバスの ​Listener​ コンポーネントの右にドラッグします。

  3. Transform Message​ 設定で、​[Output (出力)]​ セクションの括弧を次の XML で上書きします。

    {
    	"template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    	description: message.attributes.queryParams.description,
    	displayName: message.attributes.queryParams.displayName,
    	"members":[
          {
            "@odata.type":"#microsoft.graph.aadUserConversationMember",
            "user@odata.bind":"https://graph.microsoft.com/v1.0/users('" ++ message.attributes.queryParams.user as String ++ "')",
             "roles":[
                "owner"
             ]
          }
    }

Create Team 操作を追加する

Create team​ 操作では、ユーザー入力に基づいて新しいチームを作成します。

  1. [Create team]​ 操作をキャンバスの ​[Transform Message]​ コンポーネントの右にドラッグします。

  2. [Create team] の設定で、​[Connector configuration (コネクタ設定)]​ ドロップダウンをクリックし、​[Microsoft-Teams-Client-Config]​ を選択します。

  3. グローバル要素種別として ​[Microsoft_Teams_Client_Credentials_Config]​ を選択し、​[OK]​ をクリックします。

  4. [Create team] のプロパティウィンドウで、次の項目を設定します。

    項目

    Display Name (表示名)

    Create team

    Connector Configuration (コネクタ設定)

    OAuth_Client_Credentials_Config

    Message (メッセージ)

    payload

2 つ目の [Transform Message] コンポーネントを追加する

この ​Transform Message​ コンポーネントでは、​Create team​ 操作の出力を JSON 形式に変換します。

  1. [Mule Palette (Mule パレット)]​ ビューで、「​transform message​」を検索します。

  2. Transform Message​ コンポーネントをキャンバスの ​Listener​ コンポーネントの右にドラッグします。

  3. 新しい ​[Transform Message (メッセージの変換)]​ コンポーネントをクリックして、出力を ​application/json​ に設定します。

    %dw 2.0
    output application/json

チームのプロパティおよびリレーションを取得する

新しいチームのプロパティおよびリレーションを取得する 2 番目のフローを作成します。このフローでは、​Get Team​ 操作を使用します。

チームを取得するフロー
Figure 2. このようなフローを使用して、新しいチームのプロパティおよびリレーションを取得します。

チームメンバーを取得する

新しいチームのメンバーに関する情報を取得する 3 番目のフローを作成します。このフローでは、​List team members​ 操作を使用します。

チームメンバーを取得するフロー
Figure 3. このようなフローを使用して、チームメンバーに関する情報を取得します。

チームチャネルを取得する

チームで使用するチャネルに関する情報を取得する 4 番目のフローを作成します。このフローでは、​List channels​ 操作を使用します。

チームチャネルを取得するフロー
Figure 4. このようなフローを使用して、新しいチームで使用するチャネルを取得します。

チームへの新入社員のオンボーディングを行う

チームへの新入社員のオンボーディングを行う 5 番目のフローを作成します。 このフローでは、次の操作を使用します。

  • 新しいメンバーをチームに追加する ​Add team member

  • 新しいチャネルを作成する ​Create channel

  • 新しく作成されたチャネルに新しいメンバーを追加する ​Add channel member

  • ようこそメッセージを作成する ​Create message

新入社員をオンボーディングするフロー
Figure 5. このようなフローを使用して、新しいユーザーをオンボーディングします。

チームチャネルを削除する

チャネルを削除する 6 番目のフローを作成します。このフローでは、​Delete channel​ 操作を使用します。

チャネルを削除するフロー
Figure 6. このようなフローを使用して、チャネルを削除します。

チームメンバーを削除する

チームからメンバーを削除する 7 番目のフローを作成します。このフローでは、​Remove team member​ 操作を使用します。

チームメンバーを削除するフロー
Figure 7. このようなフローを使用して、チームメンバーを削除します。

アプリケーションを実行する

アプリケーションを実行する手順は、次のとおりです。

  1. Package Explorer でプロジェクトを右クリックし、​[Run As (別のユーザーとして実行)] > [Mule Application (Mule アプリケーション)]​ を選択します。

  2. アプリケーションをデプロイしたら、Web ブラウザーを開きます。

  3. http://localhost:8081/authorize​ という URL を入力して、OAuth ダンスを開始します。

  4. ログイン画面で、Microsoft Teams にアクセスするためのログイン情報を入力し、​[Login (ログイン)]​ をクリックします。

  5. [Allow (許可)]​ をクリックします。

  6. 次の表に示すように、関連付けられた URL を入力してフローを開始します。URL にクエリパラメーターがある場合、パラメーター値が含まれていることを確認します。

    Flow (フロー) URL 注意事項

    新しいチームを作成する

    http://localhost:8081/createTeam?displayName={teamDisplayName}&description={teamDescription}&user={teamOwnerUser}

    チームのプロパティおよびリレーションを取得する

    http://localhost:8081/getTeam?team={createdTeamId}

    チームチャネルを取得する

    http://localhost:8081/listChannels

    この例ではチャネルを作成しないため、デフォルトチャネルのみが返されます。

    チームへの新入社員のオンボーディングを行う

    http://localhost:8081/newHireFlow?channelName={channelName}&team={createdTeamId}&userToOnboard={userToBeOnboarded}&channelOwner={channelOwner}

    userToOnboard​ クエリパラメーターには、チャネルオーナーではないユーザーを指定します。JSON 応答には、次のようこそメッセージが含まれます。

    "content": "Welcome to the team {channelName}"

    チームチャネルを削除する

    http://localhost:8081/deleteChannel?team={teamId}&channel={channelId}

    チームメンバーの削除

    http://localhost:8081/removeTeamMembers?team={teamId}&member={membershipId}

例の XML

この XML コードをプロジェクトの ​[Configuration XML (設定 XML)]​ タブに貼り付けて、前のセクションで説明したフローを試してください。このコードを貼り付けたら、​[Regenerate 'doc:id' Values (「doc:id」値を再生成)]​ ダイアログで ​[Yes (はい)]​ をクリックします。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:microsoftTeams="http://www.mulesoft.org/schema/mule/microsoftTeams"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/microsoftTeams http://www.mulesoft.org/schema/mule/microsoftTeams/current/mule-microsoftTeams.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
	<configuration-properties file="mule-app.properties"/>
	<microsoftTeams:client-credentials-config name="OAuth_Client_Credentials_Config" doc:name="Microsoft Teams Client Credentials Config">
		<microsoftTeams:oauth-client-credentials-connection >
			<microsoftTeams:oauth-client-credentials clientId="${config.oauth.client.credentials.clientId}" clientSecret="${config.oauth.client.credentials.clientSecret}" tokenUrl="${config.oauth.client.credentials.tokenUrl}" scopes="https://graph.microsoft.com/.default" />
		</microsoftTeams:oauth-client-credentials-connection>
	</microsoftTeams:client-credentials-config>
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<http:listener-config name="auth" doc:name="HTTP Listener config" >
		<http:listener-connection host="0.0.0.0" port="8083" />
	</http:listener-config>
	<microsoftTeams:authorization-code-config name="OAuth_Authorization_Code_Config" doc:name="Microsoft Teams Authorization Code Config" >
		<microsoftTeams:oauth-authorization-code-connection >
			<microsoftTeams:oauth-authorization-code consumerKey="${config.oauth.authorization.code.consumerKey}" consumerSecret="${config.oauth.authorization.code.consumerSecret}" authorizationUrl="${config.oauth.authorization.code.authorizationUrl}" accessTokenUrl="${config.oauth.authorization.code.accessTokenUrl}" scopes="https://graph.microsoft.com/.default" />
			<microsoftTeams:oauth-callback-config listenerConfig="auth" callbackPath="/callback" authorizePath="/authorize" externalCallbackUrl="http://localhost:8083/callback" />
		</microsoftTeams:oauth-authorization-code-connection>
	</microsoftTeams:authorization-code-config>
	<flow name="1.CREATE-TEAM" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createTeam"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	"template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
	description: message.attributes.queryParams.description,
	displayName: message.attributes.queryParams.displayName,
	"members":[
      {
        "@odata.type":"#microsoft.graph.aadUserConversationMember",
        "user@odata.bind":"https://graph.microsoft.com/v1.0/users('" ++ message.attributes.queryParams.user as String ++ "')",
         "roles":[
            "owner"
         ]
      }
   ]
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<microsoftTeams:create-team doc:name="Create team" config-ref="OAuth_Client_Credentials_Config"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
	<flow name="2.GET-CREATED-TEAM">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/getTeam" />
		<microsoftTeams:get-team doc:name="Get team" teamId="#[message.attributes.queryParams.team]" select="#[message.attributes.queryParams.select]" config-ref="OAuth_Client_Credentials_Config">
			<microsoftTeams:advanced-query-params >
			</microsoftTeams:advanced-query-params>
		</microsoftTeams:get-team>
		<ee:transform doc:name="Transform Message">
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
	<flow name="3.LIST-TEAM-MEMBERS-FROM-THE-NEW-TEAM">
		<http:listener doc:name="Listener" path="/listTeamMembers" config-ref="HTTP_Listener_config"/>
		<microsoftTeams:list-team-members doc:name="List team members" teamId="#[message.attributes.queryParams.team]" config-ref="OAuth_Client_Credentials_Config"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
	<flow name="4.LIST-EXISTING-CHANNELS-FROM-THE-NEW-TEAM">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/listChannels"/>
		<microsoftTeams:list-channels doc:name="List channels" doc:id="e260eb05-4be8-4da9-9cfa-e220ecb4a49a" teamId="#[message.attributes.queryParams.team]" config-ref="OAuth_Client_Credentials_Config">
			<microsoftTeams:advanced-query-params >
			</microsoftTeams:advanced-query-params>
		</microsoftTeams:list-channels>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
message]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
	<flow name="5.NEW-HIRE-TEAM-ONBOARDING">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/newHireFlow"/>
		<set-variable value="#[message.attributes.queryParams.channelOwner]" doc:name="Set Variable" variableName="channelOwner"/>
		<set-variable value="#[message.attributes.queryParams.channelName]" doc:name="Set Variable" variableName="name"/>
		<set-variable value="#[message.attributes.queryParams.userToOnboard]" doc:name="Set Variable" variableName="userToOnboard"/>
		<set-variable value="#[message.attributes.queryParams.team]" doc:name="Set Variable" variableName="team"/>
		<microsoftTeams:add-team-member doc:name="Add team member" teamId="#[vars.team]" userId="#[vars.userToOnboard]" config-ref="OAuth_Client_Credentials_Config"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
	description: "This channel will be used to onboard new hire " ++ vars.name as String,
	displayName: "Welcome " ++ vars.name as String ++ uuid()[0 to 5],
	membershipType: "private",
	"members":
     [
        {
           "@odata.type":"#microsoft.graph.aadUserConversationMember",
           "user@odata.bind":"https://graph.microsoft.com/v1.0/users('" ++ vars.channelOwner as String ++ "')",
           "roles":["owner"]
        }
     ]
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<microsoftTeams:create-channel doc:name="Create channel" teamId="#[vars.team]" config-ref="OAuth_Client_Credentials_Config"/>
		<set-variable value="#[payload.id]" doc:name="Set Variable" variableName="channel"/>
		<microsoftTeams:add-channel-member doc:name="Add channel member" channelId="#[vars.channel]" teamId="#[vars.team]" userId="#[vars.userToOnboard]" owner="true" config-ref="OAuth_Client_Credentials_Config"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	body: {
		content: "Welcome to the team " ++ vars.name as String
	}
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<microsoftTeams:create-message doc:name="Create message" config-ref="OAuth_Authorization_Code_Config" teamId="#[vars.team]" channelId="#[vars.channel]"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
	<flow name="6.DELETE-CHANNEL-FROM-TEAM">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/deleteChannel" />
		<microsoftTeams:delete-channel doc:name="Delete channel" teamId="#[message.attributes.queryParams.team]" channelId="#[message.attributes.queryParams.channel]" config-ref="OAuth_Client_Credentials_Config"/>
	</flow>
	<flow name="7.REMOVE-TEAM-MEMBER">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/removeTeamMember" />
		<microsoftTeams:remove-team-member doc:name="Remove team member" teamId="#[message.attributes.queryParams.team]" membershipId="#[message.attributes.queryParams.member]" config-ref="OAuth_Client_Credentials_Config"/>
	</flow>
</mule>