restgolanggowhatsapp-multi-devicewhatsapp-apiwhatsappwhatsapp-web-multi-devicewhatsapp-api-gorest-apigolang-whatsapp-apigolang-whatsappbot
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
790 B
37 lines
790 B
package helpers
|
|
|
|
import (
|
|
"context"
|
|
"mime/multipart"
|
|
"time"
|
|
|
|
domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app"
|
|
"go.mau.fi/whatsmeow"
|
|
)
|
|
|
|
func SetAutoConnectAfterBooting(service domainApp.IAppUsecase) {
|
|
time.Sleep(2 * time.Second)
|
|
_ = service.Reconnect(context.Background())
|
|
}
|
|
|
|
func SetAutoReconnectChecking(cli *whatsmeow.Client) {
|
|
// Run every 5 minutes to check if the connection is still alive, if not, reconnect
|
|
go func() {
|
|
for {
|
|
time.Sleep(5 * time.Minute)
|
|
if !cli.IsConnected() {
|
|
_ = cli.Connect()
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func MultipartFormFileHeaderToBytes(fileHeader *multipart.FileHeader) []byte {
|
|
file, _ := fileHeader.Open()
|
|
defer file.Close()
|
|
|
|
fileBytes := make([]byte, fileHeader.Size)
|
|
_, _ = file.Read(fileBytes)
|
|
|
|
return fileBytes
|
|
}
|