> For the complete documentation index, see [llms.txt](https://docs-embed.anyflow.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-embed.anyflow.jp/recipe/communication/slackbot-custom-upload-file.md).

# Slack チャンネルにファイルをアップロードする

## **概要**

SlackBot アクションで、Slack チャンネルにファイルをアップロードするカスタムアクションを構築します。

## **事前準備**

クラウドストレージサービスから、ファイルをダウンロードするアクションを追加します。本レシピでは [Box](https://app.box.com/folder/0) の「ファイルをダウンロード」アクションを利用する例を解説します。

<figure><img src="https://files.readme.io/4d7530e-CleanShot_2023-12-17_at_10.29.02.png" alt=""><figcaption></figcaption></figure>

アクションを追加し、アプリケーションとして「Box」を選択します。

<figure><img src="https://files.readme.io/0eb29da-CleanShot_2023-12-17_at_10.32.14.png" alt=""><figcaption></figcaption></figure>

アクションとして「ファイルをダウンロード」を選択します。

<figure><img src="https://files.readme.io/202b448-CleanShot_2023-12-17_at_10.33.20.png" alt=""><figcaption></figcaption></figure>

ダウンロードするファイルの ID を入力します。例として、常に同じファイルをダウンロードするよう、特定ファイルの ID を入力しています。

<figure><img src="https://files.readme.io/e1acfe7-CleanShot_2023-12-17_at_10.35.50.png" alt=""><figcaption></figcaption></figure>

## **構築手順**

先に構築した「ファイルをダウンロード」アクションによってダウンロードしたファイルを、Slack のチャンネルにアップロードするカスタムアクションを構築する手順を解説します。

<figure><img src="https://files.readme.io/b837ccd-CleanShot_2023-12-17_at_10.41.38.png" alt=""><figcaption></figcaption></figure>

アクションを追加し、アプリケーションとして「Slack Bot」を選択します。

<figure><img src="https://files.readme.io/084fa46-CleanShot_2023-12-17_at_10.41.31.png" alt=""><figcaption></figcaption></figure>

アクションとして「カスタムアクション」を選択します。

<figure><img src="https://files.readme.io/8cca71b-CleanShot_2023-12-17_at_10.46.19.png" alt=""><figcaption></figcaption></figure>

カスタムアクションを設定します。

「カスタムアクション名」にはわかりやすい任意の名前を入力します。

「HTTPメソッド」には `POST` を選択します。HTTPメソッドを選択すると、追加の入力フィールドが表示されます。

<figure><img src="https://files.readme.io/5ab0513-CleanShot_2023-12-17_at_10.47.26.png" alt=""><figcaption></figcaption></figure>

リクエストパスには `/files.upload` と入力します。

<figure><img src="https://files.readme.io/379402f-CleanShot_2023-12-17_at_10.51.18.png" alt=""><figcaption></figcaption></figure>

リクエストタイプには `multipart` と入力します。Slack の特定チャンネルにファイルをアップロードするにためには、この設定が必須となります。

<figure><img src="https://files.readme.io/af87ca2-CleanShot_2023-12-17_at_10.53.31.png" alt=""><figcaption></figcaption></figure>

リクエストボディ定義に、「手動追加」をクリックして `file` と `channel` ２つの項目を追加します。

<figure><img src="https://files.readme.io/548a3db-CleanShot_2023-12-17_at_10.55.33.png" alt=""><figcaption></figcaption></figure>

`file`スキーマは以下のように設定します。型には `File` を指定します。

<figure><img src="https://files.readme.io/6a61a9c-CleanShot_2023-12-23_at_11.16.25.png" alt=""><figcaption></figcaption></figure>

`channels`スキーマは以下のように設定します。型は `String` を指定します。

<figure><img src="https://files.readme.io/e124101-image.png" alt=""><figcaption></figcaption></figure>

リクエストボディの `file` で送信する値を設定します。

<figure><img src="https://files.readme.io/efb1e81-CleanShot_2023-12-23_at_11.37.10.png" alt=""><figcaption></figcaption></figure>

`Filename` に、Slack にファイルをアップロードしたあと、どようなファイル名でSlack に保存したいかを指定します。ここでは `cat` という名前を指定しています。

`Content` に、事前準備で作成した「ファイルをダウンロード」アクションによって提供される変数を指定します。`Content` をクリックし、変数欄から「ファイルをアップロード」→「ファイル」の順番に選択します。

`Content Type` は空白のままにします。

<figure><img src="https://files.readme.io/14fb3f3-CleanShot_2023-12-23_at_11.37.57.png" alt=""><figcaption></figcaption></figure>

リクエストボディの `channel` で送信する値を指定します。

`Content` にファイルをアップロードしたい Slack のチャンネル ID を入力します。

<figure><img src="https://files.readme.io/26bbb29-CleanShot_2023-12-23_at_11.39.05.png" alt=""><figcaption></figcaption></figure>

これで Slack にファイルをアップロードするカスタムアクションが完成したので、テストを実行してみましょう。

<figure><img src="https://files.readme.io/048c098-CleanShot_2023-12-23_at_11.46.22.png" alt=""><figcaption></figcaption></figure>

上記アクションをテスト実行すると、「ファイルをダウンロード」アクションでファイルがダウンロードされていることを確認できます。

<figure><img src="https://files.readme.io/2c73a51-CleanShot_2023-12-23_at_11.48.33.png" alt=""><figcaption></figcaption></figure>

また、Slack API から返された詳細な出力値を確認し、API コールが成功したかがどうか確認可能です。

<figure><img src="https://files.readme.io/cdbaced-CleanShot_2023-12-23_at_11.48.43.png" alt=""><figcaption></figcaption></figure>

Slack の指定したチャンネルにアクセスし、ファイルが正しくアップロードされているかについても確認しましょう。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-embed.anyflow.jp/recipe/communication/slackbot-custom-upload-file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
