Merge pull request #112 from Hisoka775/master

This commit is contained in:
Edgard Lorraine Messias
2023-06-15 20:44:22 -03:00
committed by GitHub
3 changed files with 38 additions and 5 deletions

View File

@@ -52,6 +52,10 @@ type Mentionable = {
/** list of jids that are mentioned in the accompanying text */
mentions?: string[]
}
type Contextable = {
/** add contextInfo to the message */
contextInfo?: proto.IContextInfo
}
type ViewOnce = {
viewOnce?: boolean
}
@@ -98,13 +102,13 @@ export type AnyMediaMessageContent = (
image: WAMediaUpload
caption?: string
jpegThumbnail?: string
} & Mentionable & Buttonable & Templatable & WithDimensions)
} & Mentionable & Contextable & Buttonable & Templatable & WithDimensions)
| ({
video: WAMediaUpload
caption?: string
gifPlayback?: boolean
jpegThumbnail?: string
} & Mentionable & Buttonable & Templatable & WithDimensions)
} & Mentionable & Contextable & Buttonable & Templatable & WithDimensions)
| {
audio: WAMediaUpload
/** if set to true, will send as a `voice note` */
@@ -120,7 +124,7 @@ export type AnyMediaMessageContent = (
mimetype: string
fileName?: string
caption?: string
} & Buttonable & Templatable))
} & Contextable & Buttonable & Templatable))
& { mimetype?: string } & Editable
export type ButtonReplyInfo = {
@@ -138,11 +142,11 @@ export type AnyRegularMessageContent = (
text: string
linkPreview?: WAUrlInfo | null
}
& Mentionable & Buttonable & Templatable & Listable & Editable)
& Mentionable & Contextable & Buttonable & Templatable & Listable & Editable)
| AnyMediaMessageContent
| ({
poll: PollMessageOptions
} & Mentionable & Buttonable & Templatable & Editable)
} & Mentionable & Contextable & Buttonable & Templatable & Editable)
| {
contacts: {
displayName?: string

View File

@@ -42,6 +42,10 @@ export const getUrlInfo = async(
},
): Promise<WAUrlInfo | undefined> => {
try {
// retries
const retries = 0
const maxRetry = 5
const { getLinkPreview } = await import('link-preview-js')
let previewLink = text
if(!text.startsWith('https://') && !text.startsWith('http://')) {
@@ -50,6 +54,25 @@ export const getUrlInfo = async(
const info = await getLinkPreview(previewLink, {
...opts.fetchOpts,
followRedirects: 'manual',
handleRedirects: (baseURL: string, forwardedURL: string) => {
const urlObj = new URL(baseURL)
const forwardedURLObj = new URL(forwardedURL)
if(retries >= maxRetry) {
return false
}
if(
forwardedURLObj.hostname === urlObj.hostname
|| forwardedURLObj.hostname === 'www.' + urlObj.hostname
|| 'www.' + forwardedURLObj.hostname === urlObj.hostname
) {
retries + 1
return true
} else {
return false
}
},
headers: opts.fetchOpts as {}
})
if(info && 'title' in info && info.title) {

View File

@@ -498,6 +498,12 @@ export const generateWAMessageContent = async(
}
}
if('contextInfo' in message && !!message.contextInfo) {
const [messageType] = Object.keys(m)
m[messageType] = m[messageType] || {}
m[messageType].contextInfo = message.contextInfo
}
return WAProto.Message.fromObject(m)
}