チュートリアルのこのセクションでは、Salesforce ケースがエスカレーションされた場合は地域リーダーにメールを送信し、それ以外の場合は Mule アプリケーションから Slack にメッセージを送信するための条件をフローに追加する方法について説明します。
始める前に
次の手順を実行します。
-
Slack と Salesforce の設定ファイルの作成と Salesforce インテグレーションの設定。
ケースがエスカレーションされた場合の動作を定義する
Choice ルーターを使用して、特定の条件に基づいて動作を定義します。この場合、ケースがエスカレーションされた場合にメールを送信するように選択します。
-
Anypoint Code Builder で、
new-case-salesforce.xml ファイルを開きます。 -
Logger コンポーネントの
([Add component (コンポーネントを追加)]) アイコンをクリックします。
-
「choice」と入力して [Flow Control (フローコントロール)] の下の [Choice] を選択します。 -
<when/> および <otherwise/> 要素を追加します。
<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> -
変数
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) の操作を設定する必要があります。
-
Anypoint Code Builder で、
new-case-salesforce.xml ファイルを開き、<salesforce:sfdc-config/> 要素の下に新しい行を追加します。 -
「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> -
[Escalated (エスカレーション済み)] セクションの後の
([Add component (コンポーネントを追加)]) アイコンをクリックします。
-
「send」と入力して [Email (メール)] セクションから [Send] を選択します。
-
次のコードサンプルを使用して、
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> -
アプリケーションをテストできるようにするには、一時的に
<otherwise/> 要素内に <logger/> 要素を追加します。<logger doc:name="Temporary Logger" message='#["Please look into this new Case: " ++ payload]'/> -
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 アプリケーションをテストする
-
テストを効率化するには、Logger コンポーネントのブレークポイントを削除します。
-
[Run (実行)] > [Start Debugging (F5) (デバッグを開始 (F5))] を選択します。
-
アプリケーションが正常にデプロイされたら、Salesforce アカウントにログインします。
-
アプリケーションランチャーから、[サービス] を選択します。
-
[ケース] > [新規ケース] を選択します。
-
新規ケースの [状況] が [エスカレーション済み] であることを確認します。
-
数秒後、設定されたメールアカウントで、ケースで設定された情報が含まれるメールを受信していることを確認します。
Please handle this case. Case Number: 00001030, Origin: Phone, Case Type: , Priority: Medium, Status: Escalated -
「Slack インテグレーションの設定」に進み、エスカレーションされなかったケースの Slack メッセージの設定方法を確認します。