Browse Source

fix: detect og image in send link

pull/239/head
Aldino Kemal 1 year ago
parent
commit
d4755c128e
  1. 8
      readme.md
  2. 28
      src/pkg/utils/general.go
  3. 1
      src/services/send.go

8
readme.md

@ -18,6 +18,10 @@ Now that we support ARM64 for Linux:
## Feature ## Feature
- Send WhatsApp message via http API, [docs/openapi.yml](./docs/openapi.yaml) for more details - Send WhatsApp message via http API, [docs/openapi.yml](./docs/openapi.yaml) for more details
- Mention someone
- `@phoneNumber`
- example: `Hello @628974812XXXX, @628974812XXXX`
- Post Whatsapp Status
- Compress image before send - Compress image before send
- Compress video before send - Compress video before send
- Change OS name become your app (it's the device name when connect via mobile) - Change OS name become your app (it's the device name when connect via mobile)
@ -34,10 +38,10 @@ Now that we support ARM64 for Linux:
- `--webhook="http://yourwebhook.site/handler"`, or you can simplify - `--webhook="http://yourwebhook.site/handler"`, or you can simplify
- `-w="http://yourwebhook.site/handler"` - `-w="http://yourwebhook.site/handler"`
- Webhook Secret - Webhook Secret
Our webhook will be sent to you with an HMAC header and a sha256 default key `secret`.<br> Our webhook will be sent to you with an HMAC header and a sha256 default key `secret`.<br>
You may modify this by using the option below: You may modify this by using the option below:
- `--webhook-secret="secret"` - `--webhook-secret="secret"`
- For more command `./main --help` - For more command `./main --help`
## Required (without docker) ## Required (without docker)
@ -99,7 +103,7 @@ You can fork or edit this source code !
## Current API ## Current API
- [Api Specification Document](https://bump.sh/aldinokemal/doc/go-whatsapp-web-multidevice) - [Api Specification Document](https://bump.sh/aldinokemal/doc/go-whatsapp-web-multidevice)
- You can check [docs/openapi.yml](./docs/openapi.yaml) for detail API or paste
- You can check [docs/openapi.yml](./docs/openapi.yaml) for detail API then paste
to [SwaggerEditor](https://editor.swagger.io). to [SwaggerEditor](https://editor.swagger.io).
- Furthermore you can generate HTTP Client from this API using [openapi-generator](https://openapi-generator.tech/#try) - Furthermore you can generate HTTP Client from this API using [openapi-generator](https://openapi-generator.tech/#try)

28
src/pkg/utils/general.go

@ -2,7 +2,7 @@ package utils
import ( import (
"fmt" "fmt"
"github.com/PuerkitoBio/goquery"
"io"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -11,6 +11,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/PuerkitoBio/goquery"
) )
// RemoveFile is removing file with delay // RemoveFile is removing file with delay
@ -64,6 +66,8 @@ func StrToFloat64(text string) float64 {
type Metadata struct { type Metadata struct {
Title string Title string
Description string Description string
Image string
ImageThumb []byte
} }
func GetMetaDataFromURL(url string) (meta Metadata) { func GetMetaDataFromURL(url string) (meta Metadata) {
@ -89,8 +93,26 @@ func GetMetaDataFromURL(url string) (meta Metadata) {
meta.Title = element.Text() meta.Title = element.Text()
}) })
// Print the meta description
fmt.Println("Meta data:", meta)
document.Find("meta[property='og:image']").Each(func(index int, element *goquery.Selection) {
meta.Image, _ = element.Attr("content")
})
// If an og:image is found, download it and store its content in ImageThumb
if meta.Image != "" {
imageResponse, err := http.Get(meta.Image)
if err != nil {
log.Printf("Failed to download image: %v", err)
} else {
defer imageResponse.Body.Close()
imageData, err := io.ReadAll(imageResponse.Body)
if err != nil {
log.Printf("Failed to read image data: %v", err)
} else {
meta.ImageThumb = imageData
}
}
}
return meta return meta
} }

1
src/services/send.go

@ -420,6 +420,7 @@ func (service serviceSend) SendLink(ctx context.Context, request domainSend.Link
Title: proto.String(getMetaDataFromURL.Title), Title: proto.String(getMetaDataFromURL.Title),
MatchedText: proto.String(request.Link), MatchedText: proto.String(request.Link),
Description: proto.String(getMetaDataFromURL.Description), Description: proto.String(getMetaDataFromURL.Description),
JPEGThumbnail: getMetaDataFromURL.ImageThumb,
}} }}
content := "🔗 " + request.Link content := "🔗 " + request.Link

Loading…
Cancel
Save