- id: monitor_messages
name: monitor_messages
tool: CHATWORK_GET_MESSAGES
config:
- name: api_token
value: "{{secrets.CHATWORK_API_TOKEN}}"
input:
- name: room_id
value: "123456789"
- name: force
value: 1
- id: process_commands
name: process_commands
tool: PYTHON_SANDBOX_RUN
input:
- name: script
value: |
import json
import re
messages = {{steps.monitor_messages.result.messages}}
commands = []
# Look for command patterns in messages
command_patterns = {
r'/create[_\s]+task\s+(.+)': 'create_task',
r'/report\s+(.+)': 'generate_report',
r'/remind\s+(.+)': 'set_reminder',
r'/status\s*': 'show_status'
}
for message in messages[-10:]: # Check last 10 messages
body = message.get('body', '')
for pattern, command_type in command_patterns.items():
match = re.search(pattern, body, re.IGNORECASE)
if match:
commands.append({
'type': command_type,
'message_id': message.get('message_id'),
'from_account': message.get('account', {}).get('name'),
'content': match.group(1) if match.lastindex else '',
'original_message': body
})
print(json.dumps({"commands": commands}))
- id: execute_commands
name: execute_commands
tool: PYTHON_SANDBOX_RUN
input:
- name: script
value: |
import json
commands = {{steps.process_commands.result.commands}}
responses = []
for cmd in commands:
if cmd['type'] == 'create_task':
responses.append(f"✅ Task created: {cmd['content']}")
elif cmd['type'] == 'generate_report':
responses.append(f"📊 Generating report for: {cmd['content']}")
elif cmd['type'] == 'set_reminder':
responses.append(f"⏰ Reminder set for: {cmd['content']}")
elif cmd['type'] == 'show_status':
responses.append("📋 Showing current status...")
if responses:
response_text = f"🤖 Bot Response:\n" + "\n".join(responses)
else:
response_text = None
print(json.dumps({"response": response_text, "command_count": len(commands)}))
- id: send_bot_response
name: send_bot_response
tool: CHATWORK_SEND_MESSAGE
condition: "{{steps.execute_commands.result.response != null}}"
config:
- name: api_token
value: "{{secrets.CHATWORK_API_TOKEN}}"
input:
- name: room_id
value: "123456789"
- name: body
value: "{{steps.execute_commands.result.response}}"