メインコンテンツまでスキップ

Webhook API reference

Webhookは、トピック上のメッセージを消費するための追加の方法を提供します。ウェブフックが作成されると、トピックにアタッチされます。 このトピックにメッセージが公開されると、アウトバウンド http コールが Webhook コールバック url に POST されます。この Webhook に関連付けられたエンドポイントは、Momento がリクエストを POST できるようにパブリックにアクセスできる必要があります。リクエストを 受信を確認するには、元のリクエストに対して空の HTTP 2xx レスポンスを返す必要があります。もし5 秒以内に確認が取れない場合は、メッセージを削除してタイムアウトとします。

注記

Webhook に送信されたすべてのメッセージは、トピックへのサブスクリプションがあれば受信可能です。

Put Webhook API

指定された webhook で新しい webhook を生成します。

NameTypeDescription
webhookWebhook作成するウェブフック・オブジェクト
メソッド・レスポンス・オブジェクト
  • Success
    • secretString: 文字列 - ウェブフックの署名用シークレット
  • Error

具体的な情報はレスポンスオブジェクトを参照してください。

注記

Webhookはリアルタイムの更新と通知に不可欠です。成功時に提供される secretString を安全に保存してください。

Example

const webhookId: WebhookId = {
cacheName: 'exampleCache',
webhookName: 'exampleWebhook',
};

const result = await webhookClient.putWebhook(webhookId.cacheName, webhookId.webhookName, {
destination: new PostUrlWebhookDestination('https://example.com/webhook'),
topicName: 'exampleTopic',
});
if (result instanceof PutWebhook.Success) {
console.log('Webhook created successfully. Secret:', result.secret);
} else {
console.error('Error creating webhook:', result.error.message);
}

List Webhook API

特定のキャッシュのウェブフックの一覧を取得します。

NameTypeDescription
cachestringThe name of the cache to list webhooks for.
>メソッド・レスポンス・オブジェクト
  • Success
    • webhooks: Webhook の配列 - 指定したキャッシュのウェブフックのリスト
  • Error

具体的な情報はレスポンスオブジェクトを参照してください。

注記

リストウェブフックAPIは、最新のウェブフックのリストを取得するために必要な頻度で呼び出すことができます。しかし 不要な API 呼び出しを減らし、パフォーマンスを向上させるために、結果をキャッシュすることを検討してください。

Example

const cacheName: string = 'exampleCache';

const result = await webhookClient.listWebhooks(cacheName);
if (result instanceof ListWebhooks.Success) {
console.log('Webhooks retrieved successfully:', result.webhooks);
} else {
console.error('Error retrieving webhooks:', result.error.message);
}

Delete Webhook API

指定した識別子のウェブフックを削除します。

NameTypeDescription
idWebhookId削除するウェブフックの一意な識別子
メソッド・レスポンス・オブジェクト
  • Success
    • 成功の場合、追加データはありません。
  • Error

具体的な情報はレスポンスオブジェクトを参照してください。

注記

Webhook が削除されると、その Webhook はアクティブではなくなり、削除された Webhook への受信リクエストは無視されます。

Example

const webhookId: WebhookId = {
cacheName: 'exampleCache',
webhookName: 'exampleWebhook',
};

const result = await webhookClient.deleteWebhook(webhookId.cacheName, webhookId.webhookName);
if (result instanceof DeleteWebhook.Success) {
console.log('Webhook deleted successfully');
} else {
console.error('Error deleting webhook:', result.error.message);
}

Get Webhook Secret API

特定のウェブフックに関連付けられた秘密の文字列を取得します。

NameTypeDescription
idWebhookIdシークレットを取得するウェブフックの一意な識別子
メソッド・レスポンス・オブジェクト
  • Success
    • secret: 文字列 - ウェブフックの署名用シークレット
    • webhookName: string - ウェブフックの名前
    • cacheName: string - ウェブフックに関連付けられたキャッシュの名前
  • Error

具体的な情報はレスポンスオブジェクトを参照してください。

注記

署名シークレットは、受信するウェブフック・リクエストを検証するために不可欠です。取得した取得したシークレットを安全に保管・管理するようにしましょう。

Example

const webhookId: WebhookId = {
cacheName: 'exampleCache',
webhookName: 'exampleWebhook',
};

const result = await webhookClient.getWebhookSecret(webhookId.cacheName, webhookId.webhookName);
if (result instanceof GetWebhookSecret.Success) {
console.log('Webhook secret retrieved successfully:', result.secret);
} else {
console.error('Error retrieving webhook secret:', result.error.message);
}

Rotate Webhook Secret API

ウェブフックに使用されている署名秘密をローテーションします。秘密がローテーションされると、webhook のエンドポイントに送られるすべての新しい POST リクエストは、新しい秘密で署名された 'momento-signature' ヘッダを持つようになります。

NameTypeDescription
idWebhookIdシークレットをローテーションするウェブフックの一意な識別子
メソッド・レスポンス・オブジェクト
  • Success
    • secret: 文字列 - ウェブフックの新しい署名用シークレット
    • webhookName: 文字列 - ウェブフックの名前
    • cacheName: 文字列 - ウェブフックに関連付けられたキャッシュの名前
  • Error

具体的な情報はレスポンスオブジェクトを参照してください。

注記

シークレットのローテーションは元に戻せないので、以前のシークレットに対してリクエストを検証しているすべてのウェブフックを更新することが重要です。

Example

const webhookId: WebhookId = {
cacheName: 'exampleCache',
webhookName: 'exampleWebhook',
};

const result = await webhookClient.rotateWebhookSecret(webhookId.cacheName, webhookId.webhookName);
if (result instanceof RotateWebhookSecret.Success) {
console.log('Webhook secret rotated successfully:', result.secret);
} else {
console.error('Error rotating webhook secret:', result.error.message);
}

Webhook object

Webhook オブジェクトには、Webhook を作成するために必要な情報が含まれています。

NameTypeDescription
idWebhookIdウェブフックの一意な識別子
destinationWebhookDestinationウェブフックペイロードの送信先。パブリックアクセス可能でなければなりません
topicNamestringWebhook が購読されているトピックの名前

WebhookId object

WebhookId` オブジェクトはウェブフックの一意な識別子を表します。

NameTypeDescription
cacheNamestringウェブフックに関連付けられたキャッシュの名前
webhookNamestringウェブフックの名前

WebhookDestination object

WebhookDestination オブジェクトは、Webhook ペイロードの送信先に関する情報を保持します。

NameTypeDescription
postUrlstringHTTP POSTを使用してペイロードを送信するURL

FAQ

受信したWebhookリクエストを検証するには?
[ウェブフック・セキュリティページ](/ja/topics/webhooks/security)をチェックしてください。
ポストのボディ構造は?
{
cache: string;
topic: string;
event_timestamp: number;
publish_timestamp: number;
topic_sequence_number: number;
token_id: string; // is an empty string if the message was published with an api key that does not contain a token_id
text: string; // this is the message that was published
}
Webhookのサブスクリプションに失敗した場合はどうすればよいですか?

WebhookのURLが公開されており、有効であることを確認してください。よくある問題としては、間違ったキャッシュ名やトピック名、あるいはpostURL の問題などです。

ここにない質問は、Discordサーバーまでご連絡ください。サポートチャンネルで専門家にお尋ねください。