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

View File

@@ -42,6 +42,10 @@ export const getUrlInfo = async(
}, },
): Promise<WAUrlInfo | undefined> => { ): Promise<WAUrlInfo | undefined> => {
try { try {
// retries
const retries = 0
const maxRetry = 5
const { getLinkPreview } = await import('link-preview-js') const { getLinkPreview } = await import('link-preview-js')
let previewLink = text let previewLink = text
if(!text.startsWith('https://') && !text.startsWith('http://')) { if(!text.startsWith('https://') && !text.startsWith('http://')) {
@@ -50,6 +54,25 @@ export const getUrlInfo = async(
const info = await getLinkPreview(previewLink, { const info = await getLinkPreview(previewLink, {
...opts.fetchOpts, ...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 {} headers: opts.fetchOpts as {}
}) })
if(info && 'title' in info && info.title) { 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) return WAProto.Message.fromObject(m)
} }