-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Description
Estou tentando usar templates no envio de mensagens, mas sem sucesso. Já fiz diversas mudanças no código mas acabo sempre caindo em TypeError: Cannot read properties of undefined (reading '0')
Log do Evolution:
evolution_api | [Evolution API] [development-whatsapp-meta-9c8] v2.1.1 163 - Sat Jun 28 2025 14:31:45 ERROR [ChannelStartupService] [object]
evolution_api | TypeError: Cannot read properties of undefined (reading '0')
evolution_api | at os.sendMessageWithTyping (/evolution/dist/main.js:206:479)
evolution_api | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
evolution_api | at async os.templateMessage (/evolution/dist/main.js:206:4906)
evolution_api | at async zt.sendTemplate (/evolution/dist/main.js:2:20859)
evolution_api | at async nn.dataValidate (/evolution/dist/main.js:236:98590)
evolution_api | at async /evolution/dist/main.js:236:158050
evolution_api |
evolution_api | [Evolution API] v2.1.1 163 - Sat Jun 28 2025 14:31:45 ERROR [SERVER] [object]
evolution_api | {
evolution_api | event: 'error',
evolution_api | data: {
evolution_api | error: 'Bad Request',
evolution_api | message: [ "TypeError: Cannot read properties of undefined (reading '0')" ],
evolution_api | status: 400,
evolution_api | response: { message: [Array] }
evolution_api | },
evolution_api | date_time: '2025-06-28T14:31:45.301Z',
evolution_api | api_key: 'xxxxx',
evolution_api | server_url: 'http://localhost:8080'
evolution_api | }
A chamada sendo enviada:
url: https://..../message/sendTemplate/development-whatsapp-meta-9c8
Body: { number: '553xxxx32', name: 'hello_world', language: 'en_US' }
Response:
{
status: 400,
error: 'Bad Request',
response: {
message: [ "TypeError: Cannot read properties of undefined (reading '0')" ]
}
}
A documentação não fala sobre o sendTemplate, então construi a chamada no erro e acerto e lendo o código do Evolution.
O método sendMessageWithTyping() tenta acessar messageSent.messages[0], mas quando a Meta Graph API responde o TypeError: Cannot read properties of undefined (reading '0') acontece.
Enviando manualmente direto pelo Graph (sem evolution), funcionou corretamente:
url: `https://graph.facebook.com/v21.0/${config.metaPhoneNumberId}/messages`;
body: {
messaging_product: 'whatsapp',
to: '55329xx83',
type: 'template',
template: { name: 'hello_world', language: { code: 'en_US' } }
}
Response: {
messaging_product: 'whatsapp',
contacts: [ { input: '5532xxxxx83', wa_id: '5532xxxxx83' } ],
messages: [
{
id: 'wamid.HBgMNTUzMjg4xzRCNzA2NEQ3MzZBQzAzNjQ3AA==',
message_status: 'accepted'
}
]
}
Estou errando em algo ou é bug mesmo?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels