Skip to content

Commit

Permalink
UPDATED
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurboss committed Aug 28, 2024
1 parent e3cdc4e commit 0949550
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 152 deletions.
32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ module github.com/rpsoftech/whatsapp-http-api
go 1.22.1

require (
github.com/go-playground/validator/v10 v10.19.0
github.com/gofiber/fiber/v2 v2.52.4
github.com/gen2brain/go-fitz v1.23.7
github.com/go-playground/validator/v10 v10.22.0
github.com/gofiber/fiber/v2 v2.52.5
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/mattn/go-sqlite3 v1.14.22
github.com/mdp/qrterminal/v3 v3.2.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
go.mau.fi/whatsmeow v0.0.0-20240327124018-350073db195c
google.golang.org/protobuf v1.33.0
go.mau.fi/whatsmeow v0.0.0-20240625083845-6acab596dd8c
google.golang.org/protobuf v1.34.2
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gen2brain/go-fitz v1.23.7 // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
Expand All @@ -32,23 +32,23 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.52.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.mau.fi/libsignal v0.1.0 // indirect
go.mau.fi/util v0.4.1 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
go.mau.fi/util v0.5.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
rsc.io/qr v0.2.0 // indirect
)
163 changes: 163 additions & 0 deletions go.sum

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"
Expand All @@ -22,18 +21,19 @@ import (
)

var version string
var app *fiber.App

// var app *fiber.App

func main() {
println(version)

if time.Now().Unix() > 1719562963 {
println("Please Update The Binary From Keyur Shah")
println("Press Any Key To Close")
input := bufio.NewScanner(os.Stdin)
input.Scan()
return
}
// if time.Now().Unix() > 1719562963 {
// println("Please Update The Binary From Keyur Shah")
// println("Press Any Key To Close")
// input := bufio.NewScanner(os.Stdin)
// input.Scan()
// return
// }

env.CurrentDirectory = FindAndReturnCurrentDir()
go func() {
Expand Down
2 changes: 1 addition & 1 deletion suarabh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const baseUrl = "http://103.174.103.159:4000/v1"
const token = "saura"
const token = "saura1"
const method = "POST"

var mediaUrl = fmt.Sprintf("%s/send_media", baseUrl)
Expand Down
55 changes: 0 additions & 55 deletions test.go

This file was deleted.

102 changes: 51 additions & 51 deletions utility/pdf-to-thumb.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
package utility

import (
"bytes"
"fmt"
"image/jpeg"
"os"
"path/filepath"
// import (
// "bytes"
// "fmt"
// "image/jpeg"
// "os"
// "path/filepath"

"github.com/gen2brain/go-fitz"
)
// "github.com/gen2brain/go-fitz"
// )

func ExtractFirstPage(pdfBytes []byte) ([]byte, error) {
doc, err := fitz.NewFromMemory(pdfBytes)
if err != nil {
fmt.Println("Error opening PDF:", err)
return []byte{}, err
}
defer doc.Close()
// func ExtractFirstPage(pdfBytes []byte) ([]byte, error) {
// doc, err := fitz.NewFromMemory(pdfBytes)
// if err != nil {
// fmt.Println("Error opening PDF:", err)
// return []byte{}, err
// }
// defer doc.Close()

outputDir := filepath.Join(".", "output_images")
// outputDir := filepath.Join(".", "output_images")

if _, err := os.Stat(outputDir); os.IsNotExist(err) {
err := os.Mkdir(outputDir, 0755)
if err != nil {
fmt.Println("Error creating output directory:", err)
return []byte{}, err
// if _, err := os.Stat(outputDir); os.IsNotExist(err) {
// err := os.Mkdir(outputDir, 0755)
// if err != nil {
// fmt.Println("Error creating output directory:", err)
// return []byte{}, err

}
}
// }
// }

img, err := doc.Image(0)
if err != nil {
fmt.Println("Error extracting image from page:", err)
return []byte{}, err
}
// img, err := doc.Image(0)
// if err != nil {
// fmt.Println("Error extracting image from page:", err)
// return []byte{}, err
// }

// baseName := filepath.Base(pdfPath)
// // baseName := filepath.Base(pdfPath)

// outputFileName := fmt.Sprintf("first_page_%s.jpg", baseName)
// outputFilePath := filepath.Join(outputDir, outputFileName)
// // outputFileName := fmt.Sprintf("first_page_%s.jpg", baseName)
// // outputFilePath := filepath.Join(outputDir, outputFileName)

// f, err := os.Create(outputFilePath)
// if err != nil {
// fmt.Println("Error creating image file:", err)
// return err
// }
// img.
buf := new(bytes.Buffer)
// bufio.
// err := jpeg.Encode(buf, new_image, nil)
// send_s3 := buf.Bytes()
// bytes.
err = jpeg.Encode(buf, img, &jpeg.Options{Quality: jpeg.DefaultQuality})
if err != nil {
fmt.Println("Error encoding image to JPEG:", err)
return []byte{}, err
}
// // f, err := os.Create(outputFilePath)
// // if err != nil {
// // fmt.Println("Error creating image file:", err)
// // return err
// // }
// // img.
// buf := new(bytes.Buffer)
// // bufio.
// // err := jpeg.Encode(buf, new_image, nil)
// // send_s3 := buf.Bytes()
// // bytes.
// err = jpeg.Encode(buf, img, &jpeg.Options{Quality: jpeg.DefaultQuality})
// if err != nil {
// fmt.Println("Error encoding image to JPEG:", err)
// return []byte{}, err
// }

// f.Close()
// // f.Close()

// fmt.Printf("PDF first page converted to image successfully: %s\n", pdfPath)
return buf.Bytes(), nil
}
// // fmt.Printf("PDF first page converted to image successfully: %s\n", pdfPath)
// return buf.Bytes(), nil
// }
40 changes: 20 additions & 20 deletions whatsapp/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ func (connection *WhatsappConnection) sendMediaFile(to []string, fileByte []byte
docProto = &waProto.Message{
ImageMessage: &waProto.ImageMessage{
Caption: proto.String(msg),
Url: &resp.URL,
URL: &resp.URL,
Mimetype: proto.String(extensionName),
// FileName: &fileName,
DirectPath: &resp.DirectPath,
MediaKey: resp.MediaKey,
FileEncSha256: resp.FileEncSHA256,
FileSha256: resp.FileSHA256,
FileEncSHA256: resp.FileEncSHA256,
FileSHA256: resp.FileSHA256,
FileLength: &resp.FileLength,
},
}
Expand All @@ -222,13 +222,13 @@ func (connection *WhatsappConnection) sendMediaFile(to []string, fileByte []byte
docProto = &waProto.Message{
AudioMessage: &waProto.AudioMessage{
// Caption: proto.String(msg),
Url: &resp.URL,
URL: &resp.URL,
Mimetype: proto.String(extensionName),
// FileName: &fileName,
DirectPath: &resp.DirectPath,
MediaKey: resp.MediaKey,
FileEncSha256: resp.FileEncSHA256,
FileSha256: resp.FileSHA256,
FileEncSHA256: resp.FileEncSHA256,
FileSHA256: resp.FileSHA256,
FileLength: &resp.FileLength,
},
}
Expand All @@ -247,26 +247,26 @@ func (connection *WhatsappConnection) sendMediaFile(to []string, fileByte []byte
docProto = &waProto.Message{
VideoMessage: &waProto.VideoMessage{
Caption: proto.String(msg),
Url: &resp.URL,
URL: &resp.URL,
Mimetype: proto.String(extensionName),
JpegThumbnail: thumbBytes,
JPEGThumbnail: thumbBytes,
DirectPath: &resp.DirectPath,
MediaKey: resp.MediaKey,
FileEncSha256: resp.FileEncSHA256,
FileSha256: resp.FileSHA256,
FileEncSHA256: resp.FileEncSHA256,
FileSHA256: resp.FileSHA256,
FileLength: &resp.FileLength,
},
}
} else {
docProto = &waProto.Message{
VideoMessage: &waProto.VideoMessage{
Caption: proto.String(msg),
Url: &resp.URL,
URL: &resp.URL,
Mimetype: proto.String(extensionName),
DirectPath: &resp.DirectPath,
MediaKey: resp.MediaKey,
FileEncSha256: resp.FileEncSHA256,
FileSha256: resp.FileSHA256,
FileEncSHA256: resp.FileEncSHA256,
FileSHA256: resp.FileSHA256,
FileLength: &resp.FileLength,
},
}
Expand All @@ -280,21 +280,21 @@ func (connection *WhatsappConnection) sendMediaFile(to []string, fileByte []byte
docProto = &waProto.Message{
DocumentMessage: &waProto.DocumentMessage{
Caption: proto.String(msg),
Url: &resp.URL,
URL: &resp.URL,
Mimetype: proto.String(extensionName),
FileName: &fileName,
DirectPath: &resp.DirectPath,
MediaKey: resp.MediaKey,
FileEncSha256: resp.FileEncSHA256,
FileSha256: resp.FileSHA256,
FileEncSHA256: resp.FileEncSHA256,
FileSHA256: resp.FileSHA256,
FileLength: &resp.FileLength,
},
}
if strings.Contains(extensionName, "pdf") {
thumb, err := utility.ExtractFirstPage(fileByte)
if err != nil && len(thumb) > 0 {
docProto.DocumentMessage.JpegThumbnail = thumb
}
// thumb, err := utility.ExtractFirstPage(fileByte)
// if err != nil && len(thumb) > 0 {
// docProto.DocumentMessage.JPEGThumbnail = thumb
// }
}
}
}
Expand Down

0 comments on commit 0949550

Please sign in to comment.