import json import requests import os #汎用チャンネルトーク関連。 def chio_set(ch_id,gr_id,chio_token) CHANNEL_ID = ch_id#"200605" チャンネル if not CHANNEL_ID: raise RuntimeError("環境変数 CHIO_CH_ID が設定されていません") GROUP_ID = gr_id#"534868" グループ if not GROUP_ID: raise RuntimeError("環境変数 CHIO_GR_ID が設定されていません") MESSAGES_URL = f"https://desk-api.channel.io/desk/channels/{CHANNEL_ID}/groups/{GROUP_ID}/messages" X_ACCOUNT = chio_token#トークン if not X_ACCOUNT: raise RuntimeError("環境変数 CHIO_TOKEN が設定されていません") HEADERS = { "accept": "application/json", "accept-language": "ja", "content-type": "application/json", "x-account": X_ACCOUNT, } PARAMS = { "sortOrder": "desc", "limit": 50, } def send_to_channel(text): try: 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() except Exception as e: time_datetime = datetime.now() print(f"{time_datetime}[error]:message送信に失敗しました。:{e}")