Spaces:
Runtime error
Runtime error
| import os | |
| import json | |
| import time | |
| import requests | |
| from datetime import datetime | |
| # ===== 設定 ===== | |
| CHANNEL_ID = "200605" # チャンネルID | |
| GROUP_ID = "463667" # グループID | |
| MESSAGES_URL = ( | |
| f"https://desk-api.channel.io/desk/channels/" | |
| f"{CHANNEL_ID}/groups/{GROUP_ID}/messages" | |
| ) | |
| X_ACCOUNT = os.getenv("CHANNEL_IO_TOKEN") | |
| if not X_ACCOUNT: | |
| raise RuntimeError("環境変数 CHANNEL_IO_TOKEN が設定されていません") | |
| HEADERS = { | |
| "accept": "application/json", | |
| "content-type": "application/json", | |
| "x-account": X_ACCOUNT, | |
| } | |
| # ===== メッセージ送信関数 ===== | |
| def send_message(text: str): | |
| payload = { | |
| "requestId": f"desk-web-{int(time.time() * 1000)}", | |
| "blocks": [ | |
| { | |
| "type": "text", | |
| "value": text | |
| } | |
| ] | |
| } | |
| res = requests.post( | |
| MESSAGES_URL, | |
| headers=HEADERS, | |
| data=json.dumps(payload), | |
| timeout=30 | |
| ) | |
| res.raise_for_status() | |
| print("送信成功") | |
| # ===== 実行 ===== | |
| if __name__ == "__main__": | |
| time_datetime= datetime.now() | |
| print(f"実行開始{time_datetime}") | |
| send_message(f"なう: {time_datetime}") | |
| send_message(f"botですが何か?") |