Skip to content

Conversation

@bergpinheiro
Copy link
Contributor

@bergpinheiro bergpinheiro commented Oct 6, 2025

Pull Request Description

🚀 Feature: Comprehensive WhatsApp Message Templates Support for Polls, Events, and PIX Payments

This PR introduces extensive internationalization support for WhatsApp's advanced message types (polls, events, and PIX payments) across all supported locales in the Chatwoot integration, ensuring a consistent and localized user experience for global users.


📋 Overview

This feature branch implements a complete message template system that handles three new WhatsApp message types:

  • 📊 Polls - Interactive voting messages with multiple options
  • 📅 Events - Calendar events with start/end times and location details
  • 💳 PIX Payments - Brazilian instant payment system integration

🔧 Technical Implementation

Core Changes

1. Message Consumer Enhancement (src/apps/chatwoot/consumers/waha/message.any.ts)

  • Added comprehensive message processing logic for polls, events, and PIX messages
  • Implemented extractPixData() method to parse PIX payment information from WhatsApp payloads
  • Added specialized handlers for each message type with proper data validation
  • Enhanced timestamp formatting for event messages (Unix timestamp to readable dates)
  • Integrated with existing message processing pipeline

2. Template System Extension (src/apps/chatwoot/i18n/templates.ts)

  • Added new template keys for message types:
    • WA_TO_CW_MESSAGE_POLL - Poll message templates
    • WA_TO_CW_MESSAGE_EVENT - Event message templates
    • WA_TO_CW_MESSAGE_PIX - PIX payment templates
  • Defined TypeScript interfaces for type-safe template payloads
  • Added PIX-specific data structure with merchant info, payment details, and reference IDs

Internationalization Scope

3. Multi-Language Support (16 Locales)
Extended message templates to all supported languages:

  • Middle Eastern: Arabic (ar-AE), Persian (fa-IR), Hebrew (he-IL)
  • European: German (de-DE), French (fr-FR), Russian (ru-RU), Turkish (tr-TR), Ukrainian (uk-UA)
  • Asian: Chinese (zh-CN), Hindi (hi-IN), Indonesian (id-ID), Bengali (bn-BD), Punjabi (pa-PK), Urdu (ur-PK)
  • Americas: English (en-US), Spanish (es-ES), Portuguese (pt-BR)

Total Impact: 1,106 lines added across 16 locale files


📝 Message Template Examples

Poll Messages

whatsapp.to.chatwoot.message.poll: |-
  📊 **Poll**
  **{{name}}**
  {{#options}}
  - {{optionName}}
  {{/options}}

Event Messages

whatsapp.to.chatwoot.message.event: |-
  📅 **Event**
  **{{name}}**
  {{#formattedStartTime}}
  🕐 **Start:** {{formattedStartTime}}
  {{/formattedStartTime}}
  {{#location}}
  📍 **Location:** {{location}}
  {{/location}}

Location Messages (Enhanced)

whatsapp.to.chatwoot.message.location: |-
  📍 **Shared Location**
  {{#name}}
  **{{name}}**
  {{/name}}
  {{#address}}
  📍 **Address:** {{address}}
  {{/address}}
  {{#URL}}
  🌐 **Website:** {{URL}}
  {{/URL}}
  🔗 **View on map:** https://www.google.com/maps?q={{degreesLatitude}},{{degreesLongitude}}

PIX Payment Messages

whatsapp.to.chatwoot.message.pix: |-
  💳 **PIX - Copy and Paste**
  **{{merchantName}}**
  **PIX Key:** {{key}}
  **Type:** {{keyType}}
  **Amount:** R$ {{totalAmount}}

🎯 Key Features

Poll Support

  • ✅ Displays poll question and all available options
  • ✅ Handles poll creation messages from WhatsApp
  • ✅ Maintains formatting across all locales

Event Support

  • ✅ Shows event name, start/end times, and location
  • ✅ Handles both regular and canceled events
  • ✅ Converts Unix timestamps to readable date formats
  • ✅ Supports optional event details (description, location)

PIX Payment Support

  • ✅ Extracts merchant information and payment details
  • ✅ Displays PIX key, type, and amount in Brazilian Real (R$)
  • ✅ Shows reference ID for payment tracking
  • ✅ Handles PIX static code parsing from WhatsApp payloads

Location Message Enhancements

  • ✅ Improved location message formatting with structured display
  • ✅ Added support for location name, address, and website fields
  • ✅ Enhanced Google Maps integration with direct coordinate links
  • ✅ Better organization of location information with clear visual hierarchy
  • ✅ Support for both regular and live location sharing

🔄 Development Workflow

Commit 1: Core implementation with Portuguese templates and message processing logic
Commit 2: Cleanup of temporary patch files
Commit 3: Full internationalization across all 16 supported locales


✅ Testing Considerations

  • Message templates render correctly in all supported languages
  • PIX data extraction handles various payment scenarios
  • Event timestamps display in correct timezone format
  • Poll options maintain proper formatting across locales
  • Integration with existing Chatwoot message pipeline

🌍 Impact

This enhancement significantly improves the user experience for global Chatwoot users by providing:

  • Localized messaging for WhatsApp's advanced features
  • Consistent formatting across all supported languages
  • Enhanced payment tracking for Brazilian PIX transactions
  • Better event management with readable timestamps
  • Improved poll visibility in customer conversations
  • Enhanced location sharing with structured display and direct map links

The implementation maintains backward compatibility while extending the platform's capabilities to handle modern WhatsApp communication features.


📊 Commit Summary

Commit Description Files Changed Lines Added
696de948 Core implementation with Portuguese templates 5 files 284 lines
f1ae8c09 Cleanup of temporary patch files 2 files 0 lines
01369e79 Full internationalization to all locales 16 files 1,106 lines

Total: 23 files changed, 1,390 lines added

Screenshot of message templates:

  • Poll template:
poll

Event template:
event

Template for PIX(BR):
msgPix

Localization Template (Improvements):
local

I just hope you enjoy some of the code if it's useful.

patron:PRO

@nathanarend
Copy link

nathanarend commented Oct 8, 2025

+1

patron:PLUS

@devlikepro
Copy link
Contributor

devlikepro commented Oct 12, 2025

2025.10.1 - Event, Poll, PIX messages - #1460

patron:PRO

@devlikepro devlikepro closed this Oct 12, 2025
@github-actions
Copy link

Portuguese


Title:

2025.10.1 - Evento, enquete, mensagens PIX - #1460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants