mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Merge pull request #112 from Hisoka775/master
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user