> 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/release/embed.md).

# 自社プロダクトへの組み込み

## 概要

[Anyflow SDK](https://docs-embed.anyflow.jp/anyflow-sdk/docs.md)を使うことで、自社プロダクト上でAnyflow Embedのウィザードを表示・操作することができます。

<figure><img src="https://files.readme.io/ffb1c0c-Screen_Shot_2022-12-15_at_7.22.42_PM.png" alt="1680"><figcaption><p>Sales Marker のサービスに Anyflow Embed のウィザードを表示した様子</p></figcaption></figure>

## 組み込みの2ステップ

Anyflow SDKを組み込むためには、大きく分けて２つのステップが存在します。

### 1. \[バックエンド] JWT発行エンドポイントの実装

Anyflowのウィザードでは、エンドユーザーごとに認証情報やソリューションの設定内容が区別される必要があります。

エンドユーザーは自社プロダクトが指定したIDにより区別されます。

Anyflowでは、自社プロダクトとAnyflowの間でセキュアにID等のやり取りを行う方法として、**JWT**を使っています。

JWTのペイロードに、自社プロダクトのユーザーIDを指定いただくことで、Anyflowはユーザーの区別を行います。（詳細は [JWTを生成する](https://docs-embed.anyflow.jp/release/embed/generate-jwt.md) を参照してください）

このJWTをAnyflow SDK（フロントエンド）から取得できるように、サーバーのエンドポイントを実装してください。

### 2. \[フロントエンド] Anyflow SDKの実装

[Anyflow SDK](https://docs-embed.anyflow.jp/anyflow-sdk/docs.md)を使うには初期化が必要です。

```javascript
const fetchJwt = async () => {
  const res = await fetch("./path/to/your/jwt/endpoint")
  const json = await res.json()
  return json["token"]
}

AnyflowSDK.init(fetchJwt)
```

init関数の引数としてJWT発行の処理を渡すことで、Anyflow SDKが初期化されます。

<figure><img src="https://files.readme.io/44c2c6b-Screen_Shot_2022-12-15_at_7.24.35_PM.png" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="success" %}

### ヒント

[SDK組み込みツアー](https://docs-embed.anyflow.jp/release/embed/tour.md)も参考にしてください。
{% endhint %}

## シーケンス図<br>

<figure><img src="https://files.readme.io/fff3655-sequence.jpg" alt="2312"><figcaption><p>Anyflow SDKとベンダープロダクトのシーケンス図</p></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs-embed.anyflow.jp/release/embed.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
