-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05ed590
commit 6648132
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
BOT_ACCESS_TOKEN=SuperSecretToken | ||
BOT_VERIFICATION_TOKEN=SuperSecretVerificationToken | ||
WEBHOOK_SECRET=SuperSecretWebhookSecret | ||
WEBHOOK_ID=SuperSecretWebhookId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
from aiotraq import Client | ||
from aiotraq.api.webhook import post_webhook | ||
import hashlib | ||
import hmac | ||
|
||
|
||
dotenv_path = join(dirname(__file__), ".env") | ||
load_dotenv(dotenv_path) | ||
|
||
WEBHOOK_ID = os.getenv("WEBHOOK_ID") | ||
WEBHOOK_SECRET = os.getenv("WEBHOOK_SECRET") | ||
|
||
|
||
def main() -> None: | ||
client = Client(base_url="https://q.trap.jp/api/v3") | ||
|
||
with client as client: | ||
if WEBHOOK_ID is None or WEBHOOK_SECRET is None: | ||
print("WEBHOOK_ID or WEBHOOK_SECRET is not set.") | ||
return | ||
|
||
message = "Hello World!" | ||
# メッセージ本文をWebhookシークレットでHMAC-SHA1でハッシュ化した結果をhex形式で表した文字列 | ||
# https://bot-console.trap.jp/docs/webhook/send | ||
secret = hmac.new(WEBHOOK_SECRET.encode(), message.encode(), hashlib.sha1).hexdigest() | ||
|
||
result = post_webhook.sync_detailed( | ||
client=client, | ||
webhook_id=WEBHOOK_ID, | ||
body=message, | ||
x_traq_signature=secret, | ||
) | ||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |