mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-24 17:38:40 -06:00
feat: update default conversation message for template message
This commit is contained in:
parent
427c994993
commit
29cd00ddf8
@ -157,6 +157,7 @@ export class SendTemplateDto extends Metadata {
|
|||||||
language: string;
|
language: string;
|
||||||
components: any;
|
components: any;
|
||||||
webhookUrl?: string;
|
webhookUrl?: string;
|
||||||
|
message?: string;
|
||||||
}
|
}
|
||||||
export class SendContactDto extends Metadata {
|
export class SendContactDto extends Metadata {
|
||||||
contact: ContactMessage[];
|
contact: ContactMessage[];
|
||||||
|
@ -713,6 +713,20 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getTemplateMessage(message: string, parameters?: any[]) {
|
||||||
|
if (!message) return;
|
||||||
|
let transformedMessage = message;
|
||||||
|
parameters?.forEach((parameter, index) => {
|
||||||
|
transformedMessage = transformedMessage.replace(`{{${index + 1}}}`, parameter.text);
|
||||||
|
});
|
||||||
|
return transformedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getTemplateComponent(components: any[], name: string) {
|
||||||
|
const c = components.find((c) => c.type.toUpperCase() === name.toUpperCase());
|
||||||
|
return c ?? {};
|
||||||
|
}
|
||||||
|
|
||||||
protected async eventHandler(content: any) {
|
protected async eventHandler(content: any) {
|
||||||
const database = this.configService.get<Database>('DATABASE');
|
const database = this.configService.get<Database>('DATABASE');
|
||||||
const settings = await this.findSettings();
|
const settings = await this.findSettings();
|
||||||
@ -903,7 +917,13 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
quoted ? (content.context = { message_id: quoted.id }) : content;
|
quoted ? (content.context = { message_id: quoted.id }) : content;
|
||||||
message = { conversation: `▶️${message['template']['name']}◀️` };
|
|
||||||
|
const body = this.getTemplateComponent(message['template']['components'], 'body');
|
||||||
|
const templateMessage = this.getTemplateMessage(message['template']['message'], body.parameters);
|
||||||
|
|
||||||
|
message = {
|
||||||
|
conversation: templateMessage ?? `▶️${message['template']['name']}◀️`,
|
||||||
|
};
|
||||||
return await this.post(content, 'messages');
|
return await this.post(content, 'messages');
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -34,6 +34,7 @@ export const templateMessageSchema: JSONSchema7 = {
|
|||||||
language: { type: 'string' },
|
language: { type: 'string' },
|
||||||
components: { type: 'array' },
|
components: { type: 'array' },
|
||||||
webhookUrl: { type: 'string' },
|
webhookUrl: { type: 'string' },
|
||||||
|
message: { type: 'string' },
|
||||||
},
|
},
|
||||||
required: ['name', 'language'],
|
required: ['name', 'language'],
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user