diff --git a/readme.md b/readme.md index b8faa0c..495749a 100644 --- a/readme.md +++ b/readme.md @@ -18,6 +18,10 @@ Now that we support ARM64 for Linux: ## Feature - 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 video before send - 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 - `-w="http://yourwebhook.site/handler"` - Webhook Secret - Our webhook will be sent to you with an HMAC header and a sha256 default key `secret`.
You may modify this by using the option below: - `--webhook-secret="secret"` + - For more command `./main --help` ## Required (without docker) @@ -99,7 +103,7 @@ You can fork or edit this source code ! ## Current API - [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). - Furthermore you can generate HTTP Client from this API using [openapi-generator](https://openapi-generator.tech/#try) diff --git a/src/pkg/utils/general.go b/src/pkg/utils/general.go index af43d31..71685f6 100644 --- a/src/pkg/utils/general.go +++ b/src/pkg/utils/general.go @@ -2,7 +2,7 @@ package utils import ( "fmt" - "github.com/PuerkitoBio/goquery" + "io" "log" "net/http" "os" @@ -11,6 +11,8 @@ import ( "strconv" "strings" "time" + + "github.com/PuerkitoBio/goquery" ) // RemoveFile is removing file with delay @@ -64,6 +66,8 @@ func StrToFloat64(text string) float64 { type Metadata struct { Title string Description string + Image string + ImageThumb []byte } func GetMetaDataFromURL(url string) (meta Metadata) { @@ -89,8 +93,26 @@ func GetMetaDataFromURL(url string) (meta Metadata) { 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 } diff --git a/src/services/send.go b/src/services/send.go index 255c785..aa8f9a4 100644 --- a/src/services/send.go +++ b/src/services/send.go @@ -416,12 +416,13 @@ func (service serviceSend) SendLink(ctx context.Context, request domainSend.Link getMetaDataFromURL := utils.GetMetaDataFromURL(request.Link) msg := &waE2E.Message{ExtendedTextMessage: &waE2E.ExtendedTextMessage{ - Text: proto.String(fmt.Sprintf("%s\n%s", request.Caption, request.Link)), - Title: proto.String(getMetaDataFromURL.Title), - MatchedText: proto.String(request.Link), - Description: proto.String(getMetaDataFromURL.Description), + Text: proto.String(fmt.Sprintf("%s\n%s", request.Caption, request.Link)), + Title: proto.String(getMetaDataFromURL.Title), + MatchedText: proto.String(request.Link), + Description: proto.String(getMetaDataFromURL.Description), + JPEGThumbnail: getMetaDataFromURL.ImageThumb, }} - + content := "🔗 " + request.Link if request.Caption != "" { content = "🔗 " + request.Caption