@@ -64,47 +64,46 @@ const sendMessage = async (req, res) => {
6464 */
6565
6666 try {
67- const { chatId, content, contentType, options, mediaFromURLOptions = { } } = req . body
67+ const { chatId, content, contentType, options = { } , mediaFromURLOptions = { } } = req . body
6868 const client = sessions . get ( req . params . sessionId )
69+ const sendOptions = { waitUntilMsgSent : true , ...options }
6970
7071 let messageOut
7172 switch ( contentType ) {
7273 case 'string' :
73- if ( options ?. media ) {
74- const { mimetype, data, filename = null , filesize = null } = options . media
74+ if ( sendOptions ?. media ) {
75+ const { mimetype, data, filename = null , filesize = null } = sendOptions . media
7576 if ( ! mimetype || ! data ) {
7677 return sendErrorResponse ( res , 400 , 'invalid media options' )
7778 }
78- options . media = new MessageMedia ( mimetype , data , filename , filesize )
79+ sendOptions . media = new MessageMedia ( mimetype , data , filename , filesize )
7980 }
80- messageOut = await client . sendMessage ( chatId , content , options )
81+ messageOut = await client . sendMessage ( chatId , content , sendOptions )
8182 break
8283 case 'MessageMediaFromURL' : {
8384 const messageMediaFromURL = await MessageMedia . fromUrl ( content , { unsafeMime : true , ...mediaFromURLOptions } )
84- messageOut = await client . sendMessage ( chatId , messageMediaFromURL , options )
85+ messageOut = await client . sendMessage ( chatId , messageMediaFromURL , sendOptions )
8586 break
8687 }
8788 case 'MessageMedia' : {
8889 const messageMedia = new MessageMedia ( content . mimetype , content . data , content . filename , content . filesize )
89- messageOut = await client . sendMessage ( chatId , messageMedia , options )
90+ messageOut = await client . sendMessage ( chatId , messageMedia , sendOptions )
9091 break
9192 }
9293 case 'Location' : {
9394 const location = new Location ( content . latitude , content . longitude , content . description )
94- messageOut = await client . sendMessage ( chatId , location , options )
95+ messageOut = await client . sendMessage ( chatId , location , sendOptions )
9596 break
9697 }
9798 case 'Contact' : {
9899 const contactId = content . contactId . endsWith ( '@c.us' ) ? content . contactId : `${ content . contactId } @c.us`
99100 const contact = await client . getContactById ( contactId )
100- messageOut = await client . sendMessage ( chatId , contact , options )
101+ messageOut = await client . sendMessage ( chatId , contact , sendOptions )
101102 break
102103 }
103104 case 'Poll' : {
104105 const poll = new Poll ( content . pollName , content . pollOptions , content . options )
105- messageOut = await client . sendMessage ( chatId , poll , options )
106- // fix for poll events not being triggered (open the chat that you sent the poll)
107- await client . interface . openChatWindow ( chatId )
106+ messageOut = await client . sendMessage ( chatId , poll , sendOptions )
108107 break
109108 }
110109 default :
0 commit comments