Browse Source
feat: add customable params (#13)
feat: add customable params (#13)
* feat: set chrome as default platform feat: change port from setting * feat: add custom port & debugging * feat: add custom autoreply message * chore: update docs * chore: update docs * fix: typopull/14/head v3.2.0
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 198 additions and 125 deletions
-
17readme.md
-
97src/cmd/root.go
-
17src/config/settings.go
-
3src/go.mod
-
4src/go.sum
-
65src/main.go
-
4src/services/app_service_impl.go
-
54src/structs/send_struct.go
-
48src/structs/user_struct.go
-
14src/utils/whatsapp.go
@ -0,0 +1,97 @@ |
|||
package cmd |
|||
|
|||
import ( |
|||
"fmt" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/config" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/controllers" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/middleware" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/services" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/utils" |
|||
"github.com/gofiber/fiber/v2" |
|||
"github.com/gofiber/fiber/v2/middleware/cors" |
|||
"github.com/gofiber/fiber/v2/middleware/logger" |
|||
"github.com/gofiber/template/html" |
|||
"github.com/markbates/pkger" |
|||
_ "github.com/mattn/go-sqlite3" |
|||
"log" |
|||
"os" |
|||
|
|||
"github.com/spf13/cobra" |
|||
) |
|||
|
|||
// rootCmd represents the base command when called without any subcommands
|
|||
var rootCmd = &cobra.Command{ |
|||
Short: "Send free whatsapp API", |
|||
Long: `This application is from clone https://github.com/aldinokemal/go-whatsapp-web-multidevice,
|
|||
you can send whatsapp over http api but your whatsapp account have to be multi device version`, |
|||
Run: runRest, |
|||
} |
|||
|
|||
func init() { |
|||
rootCmd.CompletionOptions.DisableDefaultCmd = true |
|||
rootCmd.PersistentFlags().StringVarP(&config.AppPort, "port", "p", config.AppPort, "change port number with --port <number> | example: --port=8080") |
|||
rootCmd.PersistentFlags().BoolVarP(&config.AppDebug, "debug", "d", config.AppDebug, "hide or displaying log with --debug <true/false> | example: --debug=true") |
|||
rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyMessage, "autoreply", "", config.WhatsappAutoReplyMessage, `auto reply when received message --autoreply <string> | example: --autoreply="Don't reply this message"`) |
|||
} |
|||
|
|||
func runRest(cmd *cobra.Command, args []string) { |
|||
if config.AppDebug { |
|||
config.WhatsappLogLevel = "DEBUG" |
|||
} |
|||
|
|||
// TODO: Init Rest App
|
|||
//preparing folder if not exist
|
|||
err := utils.CreateFolder(config.PathQrCode, config.PathSendItems) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
engine := html.NewFileSystem(pkger.Dir("/views"), ".html") |
|||
app := fiber.New(fiber.Config{ |
|||
Views: engine, |
|||
BodyLimit: 10 * 1024 * 1024, |
|||
}) |
|||
app.Static("/statics", "./statics") |
|||
app.Use(middleware.Recovery()) |
|||
if config.AppDebug { |
|||
app.Use(logger.New()) |
|||
} |
|||
app.Use(cors.New(cors.Config{ |
|||
AllowOrigins: "*", |
|||
AllowHeaders: "Origin, Content-Type, Accept", |
|||
})) |
|||
|
|||
db := utils.InitWaDB() |
|||
cli := utils.InitWaCLI(db) |
|||
|
|||
// Service
|
|||
appService := services.NewAppService(cli) |
|||
sendService := services.NewSendService(cli) |
|||
userService := services.NewUserService(cli) |
|||
|
|||
// Controller
|
|||
appController := controllers.NewAppController(appService) |
|||
sendController := controllers.NewSendController(sendService) |
|||
userController := controllers.NewUserController(userService) |
|||
|
|||
appController.Route(app) |
|||
sendController.Route(app) |
|||
userController.Route(app) |
|||
|
|||
app.Get("/", func(ctx *fiber.Ctx) error { |
|||
return ctx.Render("index", fiber.Map{"AppHost": fmt.Sprintf("%s://%s", ctx.Protocol(), ctx.Hostname())}) |
|||
}) |
|||
|
|||
err = app.Listen(":" + config.AppPort) |
|||
if err != nil { |
|||
log.Fatalln("Failed to start: ", err.Error()) |
|||
} |
|||
} |
|||
|
|||
// Execute adds all child commands to the root command and sets flags appropriately.
|
|||
func Execute() { |
|||
err := rootCmd.Execute() |
|||
if err != nil { |
|||
os.Exit(1) |
|||
} |
|||
} |
|||
@ -1,5 +1,16 @@ |
|||
package config |
|||
|
|||
const PathQrCode = "statics/images/qrcode" |
|||
const PathSendItems = "statics/images/senditems" |
|||
const DBName = "hydrogenWaCli.db" |
|||
type Browser string |
|||
|
|||
var ( |
|||
AppPort string = "3000" |
|||
AppDebug bool = false |
|||
|
|||
PathQrCode string = "statics/images/qrcode" |
|||
PathSendItems string = "statics/images/senditems" |
|||
|
|||
DBName string = "hydrogenWaCli.db" |
|||
|
|||
WhatsappLogLevel string = "ERROR" |
|||
WhatsappAutoReplyMessage string |
|||
) |
|||
@ -1,64 +1,11 @@ |
|||
/* |
|||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> |
|||
|
|||
*/ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/config" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/controllers" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/middleware" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/services" |
|||
"github.com/aldinokemal/go-whatsapp-web-multidevice/utils" |
|||
"github.com/gofiber/fiber/v2" |
|||
"github.com/gofiber/fiber/v2/middleware/cors" |
|||
"github.com/gofiber/fiber/v2/middleware/logger" |
|||
"github.com/gofiber/template/html" |
|||
"github.com/markbates/pkger" |
|||
_ "github.com/mattn/go-sqlite3" |
|||
"log" |
|||
) |
|||
import "github.com/aldinokemal/go-whatsapp-web-multidevice/cmd" |
|||
|
|||
func main() { |
|||
// preparing folder if not exist
|
|||
err := utils.CreateFolder(config.PathQrCode, config.PathSendItems) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
engine := html.NewFileSystem(pkger.Dir("/views"), ".html") |
|||
app := fiber.New(fiber.Config{ |
|||
Views: engine, |
|||
BodyLimit: 10 * 1024 * 1024, |
|||
}) |
|||
app.Static("/statics", "./statics") |
|||
app.Use(middleware.Recovery()) |
|||
app.Use(logger.New()) |
|||
app.Use(cors.New(cors.Config{ |
|||
AllowOrigins: "*", |
|||
AllowHeaders: "Origin, Content-Type, Accept", |
|||
})) |
|||
|
|||
db := utils.InitWaDB() |
|||
cli := utils.InitWaCLI(db) |
|||
|
|||
// Service
|
|||
appService := services.NewAppService(cli) |
|||
sendService := services.NewSendService(cli) |
|||
userService := services.NewUserService(cli) |
|||
|
|||
// Controller
|
|||
appController := controllers.NewAppController(appService) |
|||
sendController := controllers.NewSendController(sendService) |
|||
userController := controllers.NewUserController(userService) |
|||
|
|||
appController.Route(app) |
|||
sendController.Route(app) |
|||
userController.Route(app) |
|||
|
|||
app.Get("/", func(ctx *fiber.Ctx) error { |
|||
return ctx.Render("index", fiber.Map{"AppHost": fmt.Sprintf("%s://%s", ctx.Protocol(), ctx.Hostname())}) |
|||
}) |
|||
|
|||
err = app.Listen(":3000") |
|||
if err != nil { |
|||
log.Fatalln("Failed to start: ", err.Error()) |
|||
} |
|||
cmd.Execute() |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
package structs |
|||
|
|||
import "go.mau.fi/whatsmeow/types" |
|||
|
|||
type UserInfoRequest struct { |
|||
Phone string `json:"phone" query:"phone"` |
|||
} |
|||
|
|||
type UserInfoResponseDataDevice struct { |
|||
User string |
|||
Agent uint8 |
|||
Device string |
|||
Server string |
|||
AD bool |
|||
} |
|||
|
|||
type UserInfoResponseData struct { |
|||
VerifiedName string `json:"verified_name"` |
|||
Status string `json:"status"` |
|||
PictureID string `json:"picture_id"` |
|||
Devices []UserInfoResponseDataDevice `json:"devices"` |
|||
} |
|||
|
|||
type UserInfoResponse struct { |
|||
Data []UserInfoResponseData `json:"data"` |
|||
} |
|||
|
|||
type UserAvatarRequest struct { |
|||
Phone string `json:"phone" query:"phone"` |
|||
} |
|||
|
|||
type UserAvatarResponse struct { |
|||
URL string `json:"url"` |
|||
ID string `json:"id"` |
|||
Type string `json:"type"` |
|||
} |
|||
|
|||
type UserMyPrivacySettingResponse struct { |
|||
GroupAdd string `json:"group_add"` |
|||
LastSeen string `json:"last_seen"` |
|||
Status string `json:"status"` |
|||
Profile string `json:"profile"` |
|||
ReadReceipts string `json:"read_receipts"` |
|||
} |
|||
|
|||
type UserMyListGroupsResponse struct { |
|||
Data []types.GroupInfo `json:"data"` |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue