フローロジックへの条件の追加

これは進行中のベータリリースです。ベータ状態での Anypoint Code Builder の使用には、該当するベータサービス契約条件が適用されます。

チュートリアルのこのセクションでは、Salesforce ケースがエスカレーションされた場合は地域リーダーにメールを送信し、それ以外の場合は Mule アプリケーションから Slack にメッセージを送信するための条件をフローに追加する方法について説明します。

始める前に

ケースがエスカレーションされた場合の動作を定義する

Choice ルーターを使用して、特定の条件に基づいて動作を定義します。この場合、ケースがエスカレーションされた場合にメールを送信するように選択します。

  1. Anypoint Code Builder で、​new-case-salesforce.xml​ ファイルを開きます。

  2. Logger コンポーネントの ​​ (​[Add component (コンポーネントを追加)]​) アイコンをクリックします。

    add choice router slack escalation canvas
  3. 「choice」​と入力して ​[Flow Control (フローコントロール)]​ の下の ​[Choice]​ を選択します。

  4. <when/>​ および ​<otherwise/>​ 要素を追加します。

    sync api choice when
    <choice doc:name="Choice">
       <when doc:name="When" >
    
       </when>
       <otherwise doc:name="Otherwise" >
    
       </otherwise>
    
    </choice>

    Mule フローを読みやすくするために、​<choice/>​、​<when/>​、​<otherwise/>​ 要素の名前を更新します。

    <choice doc:name="Is Case Escalated?">
      <when doc:name="Escalated" >
    
      </when>
      <otherwise doc:name="Not Escalated" >
    
      </otherwise>
    </choice>
  5. 変数 ​casestatus​ が ​[Escalated (エスカレーション済み)]​ の場合に実行されるように ​when​ 分岐を定義します。

    <choice doc:name="Is Case Escalated?">
      <when doc:name="Escalated" expression='#[vars.casestatus == "Escalated"]'>
    
      </when>
      <otherwise doc:name="Not Escalated" >
    
      </otherwise>
    </choice>

Email Connector を追加する

<when/>​ 要素を設定するには、まずメール用 Anypoint Connector (Email Connector) の操作を設定する必要があります。

  1. Anypoint Code Builder で、​new-case-salesforce.xml​ ファイルを開き、​<salesforce:sfdc-config/>​ 要素の下に新しい行を追加します。

  2. 「smtp」​と入力して ​email:smtp-config​ を選択します。

    <email:smtp-config name="Email_SMTP">
      <email:smtps-connection host="${email.host}" user="${email.username}" password="${email.password}">
       <tls:context>
         <tls:trust-store insecure="true" />
       </tls:context>
      </email:smtps-connection>
    </email:smtp-config>
  3. [Escalated (エスカレーション済み)]​ セクションの後の ​​ (​[Add component (コンポーネントを追加)]​) アイコンをクリックします。

    add email operation slack integration canvas
  4. 「send」​と入力して ​[Email (メール)]​ セクションから ​[Send]​ を選択します。

    send email slack integration canvas
  5. 次のコードサンプルを使用して、​send​ を設定します。

    <email:send config-ref="Email_SMTP" doc:name="Send Escalation Email" subject='#["Case " ++ vars.casenumber ++ " was escalated"]'>
      <email:to-addresses>
        <email:to-address value="${email.username}" />
      </email:to-addresses>
      <email:body contentType="text/html" >
        <email:content ><![CDATA[#["Please handle this case. " ++ payload]]]></email:content>
    </email:body>
    </email:send>
  6. アプリケーションをテストできるようにするには、一時的に ​<otherwise/>​ 要素内に ​<logger/>​ 要素を追加します。

    <logger doc:name="Temporary Logger" message='#["Please look into this new Case: " ++ payload]'/>
  7. Choice ルーターのすべての設定を調べます。

    <choice doc:name="Is Case Escalated?">
      <when doc:name="Escalated" expression='#[vars.casestatus == "Escalated"]'>
          <email:send config-ref="Email_SMTP" doc:name="Send Escalation Email" subject='#["Case " ++ vars.casenumber ++ " was escalated"]'>
                 <email:to-addresses>
                   <email:to-address value="${email.username}" />
                </email:to-addresses>
                <email:body contentType="text/html" >
                       <email:content ><![CDATA[#["Please handle this case. " ++ payload]]]></email:content>
                     </email:body>
               </email:send>
      </when>
      <otherwise doc:name="Not Escalated" >
        <logger doc:name="Temporary Logger" message='#["Please look into this new Case: " ++ payload]'/>
      </otherwise>
    </choice>

Mule アプリケーションをテストする

  1. テストを効率化するには、Logger コンポーネントのブレークポイントを削除します。

  2. [Run (実行)]​ > ​[Start Debugging (F5) (デバッグを開始 (F5))]​ を選択します。

  3. アプリケーションが正常にデプロイされたら、Salesforce アカウントにログインします。

  4. アプリケーションランチャー​から、​[サービス]​ を選択します。

    salesforce select service
  5. [ケース]​ > ​[新規ケース]​ を選択します。

    salesfroce create new case
  6. 新規ケースの ​[状況]​ が ​[エスカレーション済み]​ であることを確認します。

  7. 数秒後、設定されたメールアカウントで、ケースで設定された情報が含まれるメールを受信していることを確認します。

    Please handle this case. Case Number: 00001030, Origin: Phone, Case Type: , Priority: Medium, Status: Escalated
  8. 「Slack インテグレーションの設定」​に進み、エスカレーションされなかったケースの Slack メッセージの設定方法を確認します。