Preview link fix (#1548)

* Preview link fix

* Preview link refactor

* Deleted empty line

* Redundant unnecessary changes

* Added checker for http/https prefix in link

Co-authored-by: Ilya Borodin <ilya.borodin@botconversa.com.br>
This commit is contained in:
Ilya Borodin
2022-04-29 16:02:13 +03:00
committed by GitHub
parent 6ee60bff67
commit 2228da3b08
2 changed files with 10 additions and 6 deletions

View File

@@ -248,9 +248,10 @@ export const generateWAMessageContent = async(
const extContent = { text: message.text } as WATextMessage
let urlInfo = message.linkPreview
if(!urlInfo && !!options.getUrlInfo && message.text.match(URL_REGEX)) {
const matchedUrls = message.text.match(URL_REGEX)
if(!urlInfo && !!options.getUrlInfo && matchedUrls) {
try {
urlInfo = await options.getUrlInfo(message.text)
urlInfo = await options.getUrlInfo(matchedUrls[0])
} catch(error) { // ignore if fails
options.logger?.warn({ trace: error.stack }, 'url generation failed')
}