Overview

ChatWork Advanced tools provide comprehensive functionality for managing messages, tasks, and team communication in ChatWork. These tools extend beyond basic messaging to include task management, message retrieval, and workflow automation.

Key Features

  • CHATWORK_SEND_MESSAGE
    • Send messages to specific ChatWork rooms
  • CHATWORK_GET_MESSAGES
    • Retrieve messages from ChatWork rooms
  • CHATWORK_CREATE_TASK
    • Create tasks in ChatWork rooms
  • CHATWORK_GET_TASKS
    • Retrieve tasks from ChatWork rooms
  • CHATWORK_UPDATE_TASK_STATUS
    • Update the status of existing ChatWork tasks

Authentication

To use ChatWork tools, you need a ChatWork API token:
  1. Log in to your ChatWork account
  2. Go to API Token Settings
  3. Generate a new API token
  4. Copy the token for use in your workflows
Note: Treat API tokens as sensitive information and never commit them to public repositories.

Example: Basic Message Operations

- id: send_notification
  name: send_notification
  tool: CHATWORK_SEND_MESSAGE
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: body
      value: |
        [To:all] Weekly Report Update
        
        The weekly report has been completed and is now available.
        Please review the following sections:
        
        - Sales Performance: {{steps.sales_data.result.summary}}
        - Key Metrics: {{steps.metrics.result.kpi}}
        - Action Items: See tasks below
        
        Let me know if you have any questions!

- id: get_recent_messages
  name: get_recent_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: analyze_messages
  name: analyze_messages
  tool: OPENAI_INVOKE
  config:
    - name: version
      value: gpt-4
  input:
    - name: prompt
      value: |
        Analyze the following ChatWork messages and identify:
        1. Key topics discussed
        2. Action items mentioned
        3. Questions that need answers
        4. Urgent items requiring attention
        
        Messages: {{steps.get_recent_messages.result.messages}}

Example: Task Management Workflow

- id: create_project_tasks
  name: create_project_tasks
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: script
      value: |
        import json
        from datetime import datetime, timedelta
        
        # Define project tasks
        project_tasks = [
            {
                "title": "Design wireframes for new feature",
                "assignee": "12345",
                "limit_time": int((datetime.now() + timedelta(days=3)).timestamp()),
                "priority": "high"
            },
            {
                "title": "Implement backend API endpoints",
                "assignee": "67890",
                "limit_time": int((datetime.now() + timedelta(days=5)).timestamp()),
                "priority": "medium"
            },
            {
                "title": "Create unit tests for new functionality",
                "assignee": "54321",
                "limit_time": int((datetime.now() + timedelta(days=7)).timestamp()),
                "priority": "medium"
            }
        ]
        
        print(json.dumps({"tasks": project_tasks}))

- id: create_task_1
  name: create_task_1
  tool: CHATWORK_CREATE_TASK
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: body
      value: "{{steps.create_project_tasks.result.tasks[0].title}}"
    - name: to_ids
      value: "{{steps.create_project_tasks.result.tasks[0].assignee}}"
    - name: limit_time
      value: "{{steps.create_project_tasks.result.tasks[0].limit_time}}"

- id: create_task_2
  name: create_task_2
  tool: CHATWORK_CREATE_TASK
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: body
      value: "{{steps.create_project_tasks.result.tasks[1].title}}"
    - name: to_ids
      value: "{{steps.create_project_tasks.result.tasks[1].assignee}}"
    - name: limit_time
      value: "{{steps.create_project_tasks.result.tasks[1].limit_time}}"

- id: notify_task_creation
  name: notify_task_creation
  tool: CHATWORK_SEND_MESSAGE
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: body
      value: |
        [To:all] New Project Tasks Created
        
        I've created the following tasks for our new project:
        {{#each steps.create_project_tasks.result.tasks}}
        - {{title}} (Assigned to: {{assignee}})
        {{/each}}
        
        Please check your task list and let me know if you have any questions!

Example: Task Status Monitoring

- id: get_room_tasks
  name: get_room_tasks
  tool: CHATWORK_GET_TASKS
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: status
      value: "open"

- id: analyze_task_status
  name: analyze_task_status
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: script
      value: |
        import json
        from datetime import datetime
        
        tasks = {{steps.get_room_tasks.result.tasks}}
        current_time = datetime.now().timestamp()
        
        overdue_tasks = []
        due_soon_tasks = []
        normal_tasks = []
        
        for task in tasks:
            limit_time = task.get('limit_time', 0)
            
            if limit_time > 0:
                if limit_time < current_time:
                    overdue_tasks.append(task)
                elif limit_time < current_time + (24 * 60 * 60):  # Due within 24 hours
                    due_soon_tasks.append(task)
                else:
                    normal_tasks.append(task)
        
        result = {
            "overdue": len(overdue_tasks),
            "due_soon": len(due_soon_tasks),
            "normal": len(normal_tasks),
            "overdue_tasks": overdue_tasks,
            "due_soon_tasks": due_soon_tasks
        }
        
        print(json.dumps(result))

- id: send_status_update
  name: send_status_update
  tool: CHATWORK_SEND_MESSAGE
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: body
      value: |
        📊 Task Status Report
        
        ⚠️ Overdue Tasks: {{steps.analyze_task_status.result.overdue}}
        🔔 Due Soon (24h): {{steps.analyze_task_status.result.due_soon}}
        ✅ On Track: {{steps.analyze_task_status.result.normal}}
        
        {{#if steps.analyze_task_status.result.overdue_tasks}}
        🚨 Overdue Tasks Need Attention:
        {{#each steps.analyze_task_status.result.overdue_tasks}}
        - {{body}} (Assigned to: {{assigned_by_account.name}})
        {{/each}}
        {{/if}}
        
        Please update your task status if needed!

- id: update_completed_task
  name: update_completed_task
  tool: CHATWORK_UPDATE_TASK_STATUS
  config:
    - name: api_token
      value: "{{secrets.CHATWORK_API_TOKEN}}"
  input:
    - name: room_id
      value: "123456789"
    - name: task_id
      value: "987654321"
    - name: body
      value: "done"

Example: Message-Based Workflow Automation

- 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}}"

Tips and Best Practices

  • Use meaningful task titles and descriptions for better project management
  • Set appropriate due dates for tasks to maintain project timelines
  • Monitor message patterns for workflow automation opportunities
  • Use @mentions and [To:all] notifications strategically
  • Implement error handling for API rate limits
  • Store room IDs and user IDs in secrets for better security
  • Consider using webhooks for real-time message processing
  • Use task status updates to keep projects on track