messages-send,tsconfig: add poll message attributes + fix tsconfig

This commit is contained in:
Rajeh Taher
2024-10-18 09:01:09 +03:00
parent 18ac07df8e
commit 34cfa92076
2 changed files with 20 additions and 3 deletions

View File

@@ -532,7 +532,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
tag: 'message', tag: 'message',
attrs: { attrs: {
id: msgId!, id: msgId!,
type: 'text', type: getMessageType(message),
...(additionalAttributes || {}) ...(additionalAttributes || {})
}, },
content: binaryNodeContent content: binaryNodeContent
@@ -577,6 +577,15 @@ export const makeMessagesSocket = (config: SocketConfig) => {
return msgId return msgId
} }
const getMessageType = (message: proto.IMessage) => {
if(message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
return 'poll'
}
return 'text'
}
const getMediaType = (message: proto.IMessage) => { const getMediaType = (message: proto.IMessage) => {
if(message.imageMessage) { if(message.imageMessage) {
return 'image' return 'image'
@@ -760,7 +769,9 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const isDeleteMsg = 'delete' in content && !!content.delete const isDeleteMsg = 'delete' in content && !!content.delete
const isEditMsg = 'edit' in content && !!content.edit const isEditMsg = 'edit' in content && !!content.edit
const isPinMsg = 'pin' in content && !!content.pin const isPinMsg = 'pin' in content && !!content.pin
const isPollMessage = 'poll' in content && !!content.poll
const additionalAttributes: BinaryNodeAttributes = { } const additionalAttributes: BinaryNodeAttributes = { }
const additionalNodes: BinaryNode[] = []
// required for delete // required for delete
if(isDeleteMsg) { if(isDeleteMsg) {
// if the chat is a group, and I am not the author, then delete the message as an admin // if the chat is a group, and I am not the author, then delete the message as an admin
@@ -773,13 +784,20 @@ export const makeMessagesSocket = (config: SocketConfig) => {
additionalAttributes.edit = '1' additionalAttributes.edit = '1'
} else if(isPinMsg) { } else if(isPinMsg) {
additionalAttributes.edit = '2' additionalAttributes.edit = '2'
} else if(isPollMessage) {
additionalNodes.push({
tag: 'meta',
attrs: {
polltype: 'creation'
},
} as BinaryNode)
} }
if('cachedGroupMetadata' in options) { if('cachedGroupMetadata' in options) {
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.') console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.')
} }
await relayMessage(jid, fullMsg.message!, { messageId: fullMsg.key.id!, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList }) await relayMessage(jid, fullMsg.message!, { messageId: fullMsg.key.id!, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes })
if(config.emitOwnEvents) { if(config.emitOwnEvents) {
process.nextTick(() => { process.nextTick(() => {
processingMutex.mutex(() => ( processingMutex.mutex(() => (

View File

@@ -2,7 +2,6 @@
"compilerOptions": { "compilerOptions": {
"target": "es2018", "target": "es2018",
"module": "CommonJS", "module": "CommonJS",
"moduleResolution": "NodeNext",
"experimentalDecorators": true, "experimentalDecorators": true,
"allowJs": false, "allowJs": false,
"checkJs": false, "checkJs": false,