Skip to content

Commit

Permalink
fix: Improovment newsletter to send poll
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Apr 11, 2024
1 parent a041474 commit ca4382f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/chat/functions/sendRawMessage.ts
Expand Up @@ -67,18 +67,24 @@ export async function sendRawMessage(

debug(`sending message (${rawMessage.type}) with id ${rawMessage.id}`);
let result = null as any;
if (chat?.isNewsletter) {
if (rawMessage.type !== ('chat' || 'image' || 'video'))
if (chat?.isNewsletter && rawMessage.type) {
const validTypes = ['chat', 'image', 'video', 'poll_creation'];
if (!validTypes.includes(rawMessage.type))
throw new WPPError(
'type_not_valid_for_newsletter',
'Please, send a valid type for send message to newsletter. Valid types: "chat", "image", "video"'
'Please, send a valid type for send message to newsletter. Valid types: "chat", "image", "video", "poll_creation"'
);
const msg = new MsgModel(rawMessage as any);
await addNewsletterMsgsRecords([await msgDataFromMsgModel(msg)]);
const resultNewsletter = await sendNewsletterMessageJob({
type:
rawMessage.type == 'chat' && !rawMessage.editMsgType
? 'text'
: rawMessage.type == 'poll_creation'
? 'pollCreation'
: 'media',
msgData: rawMessage,
msg: new MsgModel(rawMessage as any),
type: rawMessage.type == 'chat' ? 'text' : 'media',
newsletterJid: chat.id.toString(),
});
chat.msgs.add(msg);
Expand Down
4 changes: 3 additions & 1 deletion src/whatsapp/functions/sendNewsletterMessageJob.ts
Expand Up @@ -15,14 +15,16 @@
*/

import { exportModule } from '../exportModule';
import { MsgModel } from '../models';

/** @whatsapp 397995
*/
export declare function sendNewsletterMessageJob(data: {
msgData?: any;
msg?: any;
msg?: MsgModel;
newsletterJid: string;
type: string;
editType?: 'media' | 'text';
}): Promise<{ ack: { t: number }; serverId: number; success: boolean }>;

exportModule(
Expand Down

0 comments on commit ca4382f

Please sign in to comment.