Skip to main content
Glama
Jem-HR
by Jem-HR

send_message_with_buttons

Send WhatsApp messages with interactive reply buttons to collect user responses, enabling quick selection from up to three options with optional header and footer text.

Instructions

Send a message with reply buttons (up to 3).

CONSTRAINTS:

  • Maximum 3 buttons per message

  • Button title: max 20 characters

  • Button ID (callback_data): max 256 characters

  • Header text: max 60 characters (if provided)

  • Footer text: max 60 characters (if provided)

EXAMPLE: { "to": "+1234567890", "text": "Choose an option:", "buttons": [ {"id": "option_1", "title": "Yes"}, {"id": "option_2", "title": "No"}, {"id": "option_3", "title": "Maybe"} ], "header": "Quick Question", "footer": "Select one option" }

Args: to: Phone number (with country code) or WhatsApp ID text: Message body text (main message content) buttons: List of buttons with 'id' and 'title' keys (max 3) header: Optional header text (appears above main text) footer: Optional footer text (appears below buttons) reply_to_message_id: Message ID to reply to

Returns: Dictionary with success status and message ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYes
textYes
buttonsYes
headerNo
footerNo
reply_to_message_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main implementation of send_message_with_buttons tool. This async function sends WhatsApp messages with up to 3 reply buttons. It validates constraints (button limits, title/id lengths, header/footer lengths), converts button dictionaries to PyWA Button objects, calls wa_client.send_message(), and returns success/error response with message ID.
    @mcp.tool()
    async def send_message_with_buttons(
        to: str,
        text: str,
        buttons: List[Dict[str, str]],
        header: Optional[str] = None,
        footer: Optional[str] = None,
        *,
        reply_to_message_id: Optional[str] = None,
    ) -> dict:
        """
        Send a message with reply buttons (up to 3).
        
        CONSTRAINTS:
        - Maximum 3 buttons per message
        - Button title: max 20 characters
        - Button ID (callback_data): max 256 characters
        - Header text: max 60 characters (if provided)
        - Footer text: max 60 characters (if provided)
        
        EXAMPLE:
        {
          "to": "+1234567890",
          "text": "Choose an option:",
          "buttons": [
            {"id": "option_1", "title": "Yes"},
            {"id": "option_2", "title": "No"},
            {"id": "option_3", "title": "Maybe"}
          ],
          "header": "Quick Question",
          "footer": "Select one option"
        }
        
        Args:
            to: Phone number (with country code) or WhatsApp ID
            text: Message body text (main message content)
            buttons: List of buttons with 'id' and 'title' keys (max 3)
            header: Optional header text (appears above main text)
            footer: Optional footer text (appears below buttons)
            reply_to_message_id: Message ID to reply to
        
        Returns:
            Dictionary with success status and message ID
        """
        try:
            # Validate constraints
            if len(buttons) > 3:
                return {"success": False, "error": "Maximum 3 buttons allowed"}
            
            if header and len(header) > 60:
                return {"success": False, "error": "Header text must be max 60 characters"}
                
            if footer and len(footer) > 60:
                return {"success": False, "error": "Footer text must be max 60 characters"}
            
            # Convert button dictionaries to PyWA Button objects
            button_objects = []
            for btn in buttons:
                if "id" not in btn or "title" not in btn:
                    return {"success": False, "error": "Each button must have 'id' and 'title' keys"}
                
                if len(btn["title"]) > 20:
                    return {"success": False, "error": f"Button title '{btn['title']}' exceeds 20 characters"}
                    
                if len(btn["id"]) > 256:
                    return {"success": False, "error": f"Button ID '{btn['id']}' exceeds 256 characters"}
                
                button_objects.append(Button(
                    title=btn["title"],
                    callback_data=btn["id"]
                ))
            
            result = wa_client.send_message(
                to=to,
                text=text,
                buttons=button_objects,
                header=header,
                footer=footer,
                reply_to_message_id=reply_to_message_id,
            )
            
            logger.info(f"Message with buttons sent to {to}")
            message_id = getattr(result, 'id', str(result)) if result else None
            return {"success": True, "message_id": message_id}
        except Exception as e:
            logger.error(f"Failed to send message with buttons: {str(e)}")
            return {"success": False, "error": str(e)}
  • The register_interactive_tools function that registers the send_message_with_buttons tool using the @mcp.tool() decorator at line 14. This function is called from the main register_all_tools in __init__.py to register all interactive messaging tools.
    def register_interactive_tools(mcp, wa_client: WhatsApp):
        """Register interactive messaging tools."""
        
        @mcp.tool()
        async def send_message_with_buttons(
            to: str,
            text: str,
            buttons: List[Dict[str, str]],
            header: Optional[str] = None,
            footer: Optional[str] = None,
            *,
            reply_to_message_id: Optional[str] = None,
        ) -> dict:
            """
            Send a message with reply buttons (up to 3).
            
            CONSTRAINTS:
            - Maximum 3 buttons per message
            - Button title: max 20 characters
            - Button ID (callback_data): max 256 characters
            - Header text: max 60 characters (if provided)
            - Footer text: max 60 characters (if provided)
            
            EXAMPLE:
            {
              "to": "+1234567890",
              "text": "Choose an option:",
              "buttons": [
                {"id": "option_1", "title": "Yes"},
                {"id": "option_2", "title": "No"},
                {"id": "option_3", "title": "Maybe"}
              ],
              "header": "Quick Question",
              "footer": "Select one option"
            }
            
            Args:
                to: Phone number (with country code) or WhatsApp ID
                text: Message body text (main message content)
                buttons: List of buttons with 'id' and 'title' keys (max 3)
                header: Optional header text (appears above main text)
                footer: Optional footer text (appears below buttons)
                reply_to_message_id: Message ID to reply to
            
            Returns:
                Dictionary with success status and message ID
            """
            try:
                # Validate constraints
                if len(buttons) > 3:
                    return {"success": False, "error": "Maximum 3 buttons allowed"}
                
                if header and len(header) > 60:
                    return {"success": False, "error": "Header text must be max 60 characters"}
                    
                if footer and len(footer) > 60:
                    return {"success": False, "error": "Footer text must be max 60 characters"}
                
                # Convert button dictionaries to PyWA Button objects
                button_objects = []
                for btn in buttons:
                    if "id" not in btn or "title" not in btn:
                        return {"success": False, "error": "Each button must have 'id' and 'title' keys"}
                    
                    if len(btn["title"]) > 20:
                        return {"success": False, "error": f"Button title '{btn['title']}' exceeds 20 characters"}
                        
                    if len(btn["id"]) > 256:
                        return {"success": False, "error": f"Button ID '{btn['id']}' exceeds 256 characters"}
                    
                    button_objects.append(Button(
                        title=btn["title"],
                        callback_data=btn["id"]
                    ))
                
                result = wa_client.send_message(
                    to=to,
                    text=text,
                    buttons=button_objects,
                    header=header,
                    footer=footer,
                    reply_to_message_id=reply_to_message_id,
                )
                
                logger.info(f"Message with buttons sent to {to}")
                message_id = getattr(result, 'id', str(result)) if result else None
                return {"success": True, "message_id": message_id}
            except Exception as e:
                logger.error(f"Failed to send message with buttons: {str(e)}")
                return {"success": False, "error": str(e)}
  • The register_all_tools function that orchestrates tool registration, calling register_interactive_tools(mcp, wa_client) at line 17 to register the send_message_with_buttons tool and other interactive tools.
    def register_all_tools(mcp, wa_client):
        """Register all available tools with the MCP server."""
        register_messaging_tools(mcp, wa_client)
        register_interactive_tools(mcp, wa_client)
        register_template_tools(mcp, wa_client)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well. It discloses key behavioral traits: maximum button count (3), character limits for various fields, optional parameters, and the return format. It doesn't mention rate limits, authentication needs, or error conditions, but provides substantial operational context beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, constraints, example, args, returns). Every sentence adds value, though it could be slightly more front-loaded. The example is helpful but adds length. Overall efficient with minimal waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, interactive messaging), no annotations, and the presence of an output schema, the description is complete. It covers purpose, constraints, parameter semantics, example usage, and return format. The output schema handles return values, so the description appropriately focuses on usage context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by providing detailed parameter information. The 'Args' section explains each parameter's purpose, format, and constraints. The example illustrates proper usage, and constraints clarify limits. This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Send a message with reply buttons (up to 3).' It specifies the exact action (send), resource (message), and distinctive feature (reply buttons) that differentiates it from sibling tools like 'send_message' or 'send_message_with_list'. The verb+resource combination is specific and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool: when sending messages with interactive buttons. It doesn't explicitly state when NOT to use it or name specific alternatives among siblings, but the functional scope is well-defined. The constraints section implicitly guides usage by setting boundaries.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Jem-HR/pywa-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server