Slack Connector 2.0 の例

次の例は、公開 Slack チャンネルを作成してメッセージをチャンネルに投稿し、ファイルパスを使用してファイルを Slack チャンネルにアップロードして、ファイルテキストコンテンツを Slack チャンネルにアップロードする方法を示しています。

これらの例では、一部の項目値に変数を使用しています。次のいずれかを実行できます。

  • コード内で変数を値に置き換える。

  • プロパティファイルで各変数の値を指定しておき、コネクタ設定からそのファイルを参照する。

プロパティファイルの使い方が分からない場合は、​「プロパティプレースホルダーの設定」​を参照してください。

この例を試す前に、Anypoint Studio (Studio) にアクセスし、​[Mule Palette (Mule パレット)]​ ビューに Slack Connector のエントリが表示されていることを確認します。表示されない場合、​「コネクタを Mule プロジェクトに追加する」​の手順に従ってください。

チャネルの作成

次の例は、ユーザー固有の名前で公開 Slack チャネルを作成する方法を示しています。

次のスクリーンショットは、この例のアプリケーションフローを示しています。

チャネルの作成の例で使用されるコンポーネントを示しているアプリケーションフロー
Figure 1. チャネルの作成の例のアプリケーションフロー

この例を実装するには、新規 Mule プロジェクトを作成し、HTTP リスナー、Create Channel 操作、2 つの [Transform Message] コンポーネント、1 つの [Logger (ロガー)] コンポーネントを設定する必要があります。

始める前に

この例では、接続設定と Slack アプリケーションの両方の ​channels:write​ スコープが必要です。

HTTP リスナーを設定する

ローカルホストポート ​8081​ で ​/create-channel​ パスへのコールが行われたときに Mule フローを開始するように HTTP リスナーを設定します。

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

  2. Studio で ​[HTTP]​ をクリックし、​[Listener]​ 操作をキャンバスにドラッグします。

  3. [Listener (リスナー)] プロパティウィンドウで、​[Connector configuration (コネクタ設定)]​ 項目の横にある ​[+]​ をクリックしてグローバル要素を追加します。

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

  5. [Listener (リスナー)] プロパティウィンドウで、​[Path (パス)]​ 項目値を ​/create-channel​ に設定します。

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

最初の [Transform Message] コンポーネントではチャネル名を入力として受け取り、名前を JSON 形式に変換します。

  1. [Mule Palette (Mule パレット)]​ ビューで ​[Core (コア)]​ を選択して ​[Transform Message]​ コンポーネントを ​[Listener (リスナー)]​ の右側にドラッグします。

  2. [Transform Message]​ コンポーネントの名前を ​Channel Details​ に変更します。

  3. [Transform Message]​ コンポーネントをクリックし、チャネル名を出力に追加して、出力形式を ​application/json​ に設定します。

チャネル名を JSON 形式で指定している [Transform Message] コンポーネント
Figure 2. チャネルの作成の例の最初の [Transform Message] コンポーネント

Create Channel 操作を追加する

Create Channel 操作では Slack に接続し、要求を ​https://slack.com/api/conversations.create​ エンドポイントに投稿します。

  1. [Mule Palette (Mule パレット)]​ ビューから、​[Slack]​ を選択して ​[Create Channel]​ 操作を ​[Listener (リスナー)]​ の右側にドラッグします。

  2. [Search properties (検索プロパティ)] ウィンドウで、​[Connector configuration (コネクタ設定)]​ 項目の横にある ​[+]​ をクリックしてグローバル要素を追加します。

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

    項目

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

    ${consumer.key}

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

    ${consumer.secret}

    Authorization url (認証 URL)

    https://slack.com/oauth/authorize

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

    https://slack.com/api/oauth.access

    スコープ

    channels:write groups:write im:write mpim:write users:read.email

    Listener config (リスナー設定)

    HTTP_Listener-config

  4. [Slack properties (Slack プロパティ)] ウィンドウで、​[Conversationcreate content (Conversationcreate のコンテンツ)]​ 項目に「​payload​」と入力します。

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

2 番目の [Transform Message] コンポーネントでは、​Create Channel​ 操作の結果を JSON 形式に変換します。

  1. [Mule Palette (Mule パレット)]​ ビューで ​[Core (コア)]​ を選択して ​[Transform Message]​ コンポーネントを ​[Listener (リスナー)]​ の右側にドラッグします。

  2. [Transform Message]​ コンポーネントの名前を ​Payload as JSON​ に変更します。

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

    Create Channel 操作の出力を JSON 形式に変換する [Transform Message] コンポーネント
    Figure 3. チャネルの作成の例の 2 番目の [Transform Message] コンポーネント

[Logger (ロガー)] コンポーネントを追加する

[Logger (ロガー)] コンポーネントでは、クエリ結果がコンソールに記録されます。

  1. [Mule Palette (Mule パレット)]​ ビューで ​[Core (コア)]​ を選択し、​[Logger (ロガー)]​ コンポーネントを選択します。

  2. [Logger (ロガー)]​ コンポーネントを設定します。

  3. プロジェクトを保存します。

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

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

  1. Mule アプリケーションを起動します。

  2. 要求を送信するには、OAuth ダンスを実行する必要があります。ブラウザーを開き、​http://localhost:8082/authorize​ に移動して、アプリケーションにアクセスできるようにします。

  3. POST 要求を ​http://localhost:8081/account?name="your channel name"​ に送信します。

この例の XML コード

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

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

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:slack="http://www.mulesoft.org/schema/mule/slack"
	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/slack http://www.mulesoft.org/schema/mule/slack/current/mule-slack.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
	<slack:config name="Slack_Connector_Config" doc:name="Slack Connector Config"  >
		<slack:slack-auth-connection >
			<slack:oauth-authorization-code consumerKey="${consumer.key}" consumerSecret="${consumer.secret}" scopes="channels:write groups:write im:write mpim:write users:read.email "/>
			<slack:oauth-callback-config listenerConfig="HTTP_Listener_config" callbackPath="/callback" authorizePath="/authorize" externalCallbackUrl="http://localhost:8081/callback"/>
		</slack:slack-auth-connection>
	</slack: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>
	<configuration-properties doc:name="Configuration properties" file="application.properties" />
	<flow name="create-channel-flow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/create-channel"/>
		<ee:transform doc:name="Channel Details" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	name: "your-channel-name"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<slack:create-conversationscreate doc:name="Create Channel" config-ref="Slack_Connector_Config"/>
		<ee:transform doc:name="Payload as Json" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Result" message="#[payload]"/>
	</flow>
  <flow name="send-message-to-channel-flow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/send-message"/>
		<ee:transform doc:name="Message Details" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	channel: "your-existing-channel",
	text: "Your text goes here"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<slack:create-chatpost-message doc:name="Send Message" config-ref="Slack_Connector_Config"/>
		<ee:transform doc:name="Payload as Json" >
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Result" message="#[payload]"/>
	</flow>
</mule>

チャネルへのメッセージの投稿

次の例では、メッセージを公開、非公開、またはダイレクトメッセージ (IM) チャネルに投稿する方法を示しています。

次のスクリーンショットは、この例のアプリケーションフローを示しています。

チャネルへのメッセージの投稿の例で使用されるコンポーネントを示しているアプリケーションフロー
Figure 4. チャネルへのメッセージの投稿の例のアプリケーションフロー

始める前に

この例では、接続設定と Slack アプリケーションの両方の次のスコープが必要です。

  • chat:write

  • chat:write:user

  • chat:write:bot

コンポーネント

この例では、次のコンポーネントを使用します。

  • HTTP Listener (HTTP リスナー)

    ローカルホストポート 8081 で ​/send/message​ パスへのコールが行われたときに Mule フローを開始します。

  • 最初の [Transform Message] コンポーネント

    対象チャネルを指定し、Send Message 操作のメッセージコンテンツを提供します。

  • Send Message 操作

    Slack に接続し、メッセージを指定されたチャネルに投稿します。

  • 2 番目の [Transform Message] コンポーネント

    Send Message 操作の結果を JSON 形式で出力します。

  • ロガー

    Send Message 操作の結果をコンソールに記録します。

この例の XML コード

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

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

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:slack="http://www.mulesoft.org/schema/mule/slack"
	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/slack http://www.mulesoft.org/schema/mule/slack/current/mule-slack.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
	<slack:config name="Slack_Connector_Config" doc:name="Slack Connector Config" >
		<slack:slack-auth-connection >
			<slack:oauth-authorization-code consumerKey="${consumer.key}" consumerSecret="${consumer.secret}" scopes="channels:write groups:write im:write mpim:write users:read.email "/>
			<slack:oauth-callback-config listenerConfig="HTTP_Listener_config" callbackPath="/callback" authorizePath="/authorize" externalCallbackUrl="http://localhost:8081/callback"/>
		</slack:slack-auth-connection>
	</slack: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>
	<configuration-properties doc:name="Configuration properties" file="application.properties" />
	<flow name="find-user-by-email-flow"  >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="find-by-email"/>
		<slack:get-userslookup-by-email doc:name="Find User by Email" config-ref="Slack_Connector_Config" email="example@emailaddress.com"/>
		<ee:transform doc:name="Payload as Json" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Lookup Result" message="#[payload]"/>
	</flow>
  <flow name="send-message-to-channel-flow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/send-message"/>
		<ee:transform doc:name="Message Details"  >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	channel: "your-existing-channel",
	text: "Your text goes here"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<slack:create-chatpost-message doc:name="Send Message" config-ref="Slack_Connector_Config"/>
		<ee:transform doc:name="Payload as Json" >
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Result" message="#[payload]"/>
	</flow>
</mule>

Slack チャンネルへのファイルのアップロード (ファイルパスを使用)

次の例では、ファイルを公開または非公開チャンネルにアップロードする方法を示しています。

次のスクリーンショットは、この例のアプリケーションフローを示しています。

Slack へのファイルのアップロードに使用されるコンポーネントが表示されているアプリケーションフロー
Figure 5. ファイルパスを使用してファイルをチャンネルにアップロードするアプリケーションフローの例

始める前に

この例では、接続設定と Slack アプリケーションの両方の次のスコープが必要です。

  • files:write

  • files:write:user

コンポーネント

この例では、次のコンポーネントを使用します。

  • HTTP Listener (HTTP リスナー)

    ローカルホストポート 8081 で ​/file-upload​ パスへのコールが行われたときに Mule フローを開始します。

  • Read 操作 - File Connector

    指定したファイルパスからファイルを読み取ります。

  • 最初の Set Variable コンポーネント

    前のステップで取得したファイルコンテンツを ​fileContent​ という名前の変数に保存します。

  • Get upload url 操作

    Slack に対する GET 要求を実行します。必須項目として ​filename (ファイル名)​ と ​length (長さ)​ が必要であり、これらは Read 操作から取得される ​attributes.fileName​ および ​attributes.size​ として提供されます。

  • 2 つ目の Set Variable コンポーネント

    Get upload url 操作から取得された ​file_id​ を ​fileId​ という名前の変数に保存します。

  • Request 操作 - HTTP Connector

    Get upload url 操作の応答から取得されたファイルコンテンツを使用して、Slack に対する POST 要求を実行します。URL は ​[payload.upload_url]​ に設定され、コンテンツは ​[vars.fileContent]​ に設定されます。

  • Transform Message

    前のステップから取得された ​fileId (項目)​ を使用してファイルの配列を形成します。

  • Complete Upload External 操作

    Slack に対する POST 要求を実行してファイルアップロードプロセスを完了します。必須パラメーターとしてファイルの配列が必要です。

    チャンネル ID​ が指定されない場合、ファイルは Slack サーバーにアップロードされ、非公開のままになります。
  • ロガー

    Complete Upload External 操作の結果をコンソールに記録します。

この例の XML コード

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

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

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:slack="http://www.mulesoft.org/schema/mule/slack" 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/slack http://www.mulesoft.org/schema/mule/slack/current/mule-slack.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
	<slack:config name="Slack_Connector_Config" doc:name="Slack Connector Config" >
		<slack:slack-auth-connection >
			<slack:oauth-authorization-code consumerKey="${consumer.key}" consumerSecret="${consumer.secret}" scopes="channels:write groups:write im:write mpim:write users:read.email "/>
			<slack:oauth-callback-config listenerConfig="HTTP_Listener_config" callbackPath="/callback" authorizePath="/authorize" externalCallbackUrl="http://localhost:8081/callback"/>
		</slack:slack-auth-connection>
	</slack:config>
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="4e474318-0d25-4a26-b1d9-53f8b452c98f" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<configuration-properties doc:name="Configuration properties" doc:id="8fd46949-d3c3-49e6-9314-1c7edaa76e96" file="application.properties" />
	<file:config name="File_Config" doc:name="File Config" doc:id="56c48fe4-fd75-47d7-832e-e075cd7ef25f" >
		<file:connection workingDir="/Users/Test/Downloads/" />
	</file:config>
	<flow name="upload-file-to-slack" doc:id="781e1b2a-120a-406b-a9d4-77d239eca9fe" >
	<http:listener doc:name="Listener" doc:id="9f5150f9-d991-40d6-a69b-81ee6baf934f" config-ref="HTTP_Listener_config" path="/file-upload"/>
		<file:read doc:name="Read" doc:id="3b7e29dc-e86b-4da8-8974-7d0e3cd426ca" config-ref="File_Config" path="/Users/Test/Downloads/file.json"/>
            <set-variable doc:name="Set Variable" doc:id="46b7c90f-23a1-4950-8b22-6247225258a5" variableName="fileContent" value="#[payload]"/>
            <slack:get-filesget-upload-urlexternal doc:name="Get upload url" doc:id="1479ee6f-46bc-4583-b4af-561a750cc7da" config-ref="Slack_Connector_Config" length="#[attributes.size]" filename="#[attributes.fileName]"/>
            <set-variable value="#[payload.file_id]" doc:name="Set Variable" doc:id="530368e3-5691-4cca-82e1-af2214aac0f9" variableName="fileId"/>
            <http:request method="POST" doc:name="Request" doc:id="0ac21f20-9351-4b17-83ec-0efc8448c124" url="#[payload.upload_url]" responseTimeout="#[900000]">
                <http:body ><![CDATA[#[vars.fileContent]]]></http:body>
            </http:request>
            <ee:transform doc:name="Transform Message" doc:id="04f725ee-846e-49f9-90a7-94c33362b0c0" >
                <ee:message >
                    <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
write(
    [
        { id : vars.fileId }
    ],
    "application/json"
)
]]></ee:set-payload>
                </ee:message>
            </ee:transform>
            <slack:create-filescomplete-upload-external doc:name="Complete Upload External" doc:id="56fec9a8-d023-4bbb-a9ca-d5193fd4a1e0" config-ref="Slack_Connector_Config" channelId="${channel.id}" initialComment="Initial Comment" target="completeUploadExt">
                <slack:files >
                    <slack:file value="#[payload]" />
                </slack:files>
            </slack:create-filescomplete-upload-external>
		<logger level="INFO" doc:name="Logger" doc:id="38d1cd87-21f0-4f95-81c1-03806cd61d93" />
            </flow>
</mule>

Slack チャンネルへのファイルテキストコンテンツのアップロード

次の例では、ファイルテキストコンテンツを公開または非公開チャンネルにアップロードする方法を示しています。

次のスクリーンショットは、この例のアプリケーションフローを示しています。

Slack へのファイルのアップロードに使用されるコンポーネントが表示されているアプリケーションフロー
Figure 6. ファイルコンテンツをチャンネルにアップロードするアプリケーションフローの例

始める前に

この例では、接続設定と Slack アプリケーションの両方の次のスコープが必要です。

  • files:write

  • files:write:user

コンポーネント

この例では、次のコンポーネントを使用します。

  • HTTP Listener (HTTP リスナー)

    ローカルホストポート 8081 で ​/file-upload​ パスへのコールが行われたときに Mule フローを開始します。

  • Set Payload

    ファイルテキストコンテンツをペイロードに設定します。

  • 最初の Set Variable コンポーネント

    ファイルテキストコンテンツペイロードを ​UploadContent​ という名前の変数に保存します。

  • Get upload url 操作

    Slack に対する GET 要求を実行します。必須項目として ​filename (ファイル名)​ と ​length (長さ)​ が必要であり、​attributes.fileName​ および ​attributes.size​ として提供されます。

  • 2 つ目の Set Variable コンポーネント

    Get upload url 操作から取得された ​file_id​ を ​fileId​ という名前の変数に保存します。

  • Request 操作 - HTTP Connector

    Get upload url 操作の応答から取得されたファイルコンテンツを使用して、Slack に対する POST 要求を実行します。URL は ​[payload.upload_url]​ に設定され、コンテンツは ​[vars.fileContent]​ に設定されます。

  • Transform Message

    前のステップから取得された ​fileId (項目)​ を使用してファイルの配列を形成します。

  • Complete Upload External 操作

    Slack に対する POST 要求を実行してファイルアップロードプロセスを完了します。必須パラメーターとしてファイルの配列が必要です。

    チャンネル ID​ が指定されない場合、ファイルは Slack サーバーにアップロードされ、非公開のままになります。
  • ロガー

    Complete Upload External 操作の結果をコンソールに記録します。

この例の XML コード

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

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

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:slack="http://www.mulesoft.org/schema/mule/slack" 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/slack http://www.mulesoft.org/schema/mule/slack/current/mule-slack.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
	<slack:config name="Slack_Connector_Config" doc:name="Slack Connector Config" >
		<slack:slack-auth-connection >
			<slack:oauth-authorization-code consumerKey="${consumer.key}" consumerSecret="${consumer.secret}" scopes="channels:write groups:write im:write mpim:write users:read.email "/>
			<slack:oauth-callback-config listenerConfig="HTTP_Listener_config" callbackPath="/callback" authorizePath="/authorize" externalCallbackUrl="http://localhost:8081/callback"/>
		</slack:slack-auth-connection>
	</slack:config>
	<http:listener-config name="HTTP_Listener_config1" doc:name="HTTP Listener config" doc:id="84e1326d-0ae0-4f90-b38e-ff630cb9f825" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<configuration-properties doc:name="Configuration properties" doc:id="0fcec471-c686-49c7-9cf6-a94b7561cd20" file="application.properties" />
	<file:config name="File_Config" doc:name="File Config" doc:id="d1713841-299b-4778-9f04-567c174701aa" >
		<file:connection workingDir="/Users/Test/Downloads" />
	</file:config>
	<flow name="upload-file-content-to-slack" doc:id="a3f1489d-581d-4773-afda-4796c31715da" >
	<http:listener doc:name="Listener" doc:id="ec5e3594-6e87-4a14-ba89-101b91f151ef" config-ref="HTTP_Listener_config1" path="/file-upload-content"/>
            <set-payload value='#["Content"]' doc:name="Set Payload" doc:id="b65bde4b-664b-4804-9917-bc93a53295d4" />
            <set-variable value="#[payload]" doc:name="Set Variable" doc:id="1d99cd3f-93bf-4d0c-82d7-2eb65715e9db" variableName="UploadContent"/>
		<slack:get-filesget-upload-urlexternal doc:name="Get upload url" doc:id="7d71fc2e-06f8-4b72-ac61-4094c115c1fe" config-ref="Slack_Connector_Config" length="#[sizeOf(vars.UploadContent)]" filename="testfile.txt"/>
            <set-variable value="#[payload.file_id]" doc:name="Set Variable" doc:id="216a7359-ce22-436f-bdbf-067511bded6f" variableName="fileId"/>
            <http:request method="POST" doc:name="Request" doc:id="3b68d9e7-90d5-4dcb-b7db-8708a396dd27" url="#[payload.upload_url]" responseTimeout="#[900000]">
			<http:body ><![CDATA[#[vars.UploadContent]]]></http:body>
            </http:request>
            <ee:transform doc:name="Transform Message" doc:id="cff36871-94ed-484e-929a-ae29b9964adc" >
                <ee:message >
                    <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
write(
    [
        { id : vars.fileId }
    ],
    "application/json"
)
]]></ee:set-payload>
                </ee:message>
            </ee:transform>
            <slack:create-filescomplete-upload-external doc:name="Complete Upload External" doc:id="1b08e782-4ce8-4c53-b266-9407d6dcca9c" config-ref="Slack_Connector_Config" channelId="${channel.id}" initialComment="Initial Comment" target="completeUploadExt">
			<slack:files />
            </slack:create-filescomplete-upload-external>
		<logger level="INFO" doc:name="Logger" doc:id="2b467bc3-97ac-4f8d-b941-b529ee30bea3" />
            </flow>
</mule>