| メソッド | パス | 説明 |
|---|---|---|
| POST | /relay/webhook | Discord にメッセージを転送 |
| GET | /relay/webhook/status | 設定状態を確認 |
DISCORD_WEBHOOK_URLS を使う場合
curl -X POST http://localhost:3000/relay/webhook \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RELAY_TOKEN" \
-d '{"content": "Hello!", "username": "Bot"}'
送信元で宛先を指定する場合
curl -X POST http://localhost:3000/relay/webhook \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RELAY_TOKEN" \
-d '{"webhook_url": "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN", "content": "Hello!"}'
DISCORD_WEBHOOK_URLS をサーバー側で設定している場合
function sendDiscordRelay() {
const endpoint = 'https://YOUR_INTERNAL_WEB_URL/relay/webhook';
const relayToken = PropertiesService
.getScriptProperties()
.getProperty('RELAY_TOKEN');
const payload = {
content: 'GAS からの通知です',
username: 'GAS Bot'
};
const response = UrlFetchApp.fetch(endpoint, {
method: 'post',
contentType: 'application/json',
headers: {
Authorization: `Bearer ${relayToken}`
},
payload: JSON.stringify(payload),
muteHttpExceptions: true
});
Logger.log(response.getResponseCode());
Logger.log(response.getContentText());
}
GAS 側で宛先 webhook URL を指定する場合
function sendDiscordRelayWithWebhookUrl() {
const endpoint = 'https://YOUR_INTERNAL_WEB_URL/relay/webhook';
const relayToken = PropertiesService
.getScriptProperties()
.getProperty('RELAY_TOKEN');
const payload = {
webhook_url: 'https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN',
content: 'GAS から宛先を指定して送信します',
username: 'GAS Bot'
};
const response = UrlFetchApp.fetch(endpoint, {
method: 'post',
contentType: 'application/json',
headers: {
Authorization: `Bearer ${relayToken}`
},
payload: JSON.stringify(payload),
muteHttpExceptions: true
});
Logger.log(response.getResponseCode());
Logger.log(response.getContentText());
}
RELAY_TOKEN は GAS の「プロジェクトの設定」→「スクリプト プロパティ」に保存してください。
{
"webhook_url": "https://discord.com/api/webhooks/...", // 省略可
"content": "テキスト", // Discord webhook に渡す payload
"username": "表示名", // 省略可
"avatar_url": "https://...", // 省略可
"embeds": [{ "title": "..." }] // 省略可
}
| 項目 | 内容 |
|---|---|
| 認証 | RELAY_TOKEN が一致する場合のみ送信 |
| 宛先指定 | RELAY_TOKEN が一致する場合のみ有効 |
| 許可 URL | https://discord.com/api/webhooks/... または https://discordapp.com/api/webhooks/... |
| 転送内容 | webhook_url / webhook_urls / relay_token は Discord に送信しません |