diff --git a/.gitignore b/.gitignore index fa5f2d7..6225d12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea .env crm-tickets -examplestore.db \ No newline at end of file +store_whatsapp.db \ No newline at end of file diff --git a/Makefile b/Makefile index 22e5930..5406859 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,10 @@ -# Set the compiler to use for building the program -CC=go -# Set the options to use when compiling the program -GOFLAGS=-ldflags="-s -w" - -# Set the name of the output binary -OUTPUT=crm-tickets - -# Set the list of source files to compile - -# Set the GOOS environment variable to "linux" +OUTPUT=go-whatsapp export GOOS=linux export CGO_ENABLED=0 # Define the build target build: - $(CC) build -a -installsuffix cgo $(GOFLAGS) -o $(OUTPUT) main.go + go build -o $(OUTPUT) main.go # Define the clean target clean: diff --git a/README.md b/README.md index 256e704..d3dd6d8 100644 Binary files a/README.md and b/README.md differ diff --git a/go-whatsapp b/go-whatsapp deleted file mode 100755 index 325b0d3..0000000 Binary files a/go-whatsapp and /dev/null differ diff --git a/main.go b/main.go index 6e460be..2aa7f9a 100644 --- a/main.go +++ b/main.go @@ -29,21 +29,27 @@ func main() { c.JSON(http.StatusOK, gin.H{ "contact": "nandarusfikri@gmail.com", "message": "Whatsapp Gateway", + "Author": "NandaRusfikri", }) }) - router.POST("/", func(c *gin.Context) { + router.POST("/send_message", func(c *gin.Context) { var input Message if err := c.ShouldBindJSON(&input); err != nil { c.Abort() return } - sendMessage(conn, input.Phone, input.Message) + if err := sendMessage(conn, input.DestinationNumber, input.Message); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "status": "failed", + "message": err.Error(), + }) + } c.JSON(http.StatusOK, gin.H{ "status": "success", "message": "Pesan berhasil dikirim", - "nomor": input.Phone, + "nomor": input.DestinationNumber, "pesan": input.Message, }) }) @@ -61,8 +67,8 @@ func main() { } type Message struct { - Phone string `json:"phone" binding:"required"` - Message string `json:"message" binding:"required"` + DestinationNumber string `json:"destination_number" binding:"required"` + Message string `json:"message" binding:"required"` } func eventHandler(evt interface{}) { @@ -94,7 +100,7 @@ func sendMessage(client *whatsmeow.Client, phone string, message string) error { func Connect() *whatsmeow.Client { dbLog := waLog.Stdout("Database", "DEBUG", true) // Make sure you add appropriate DB connector imports, e.g. github.com/mattn/go-sqlite3 for SQLite - container, err := sqlstore.New("sqlite3", "file:examplestore.db?_foreign_keys=on", dbLog) + container, err := sqlstore.New("sqlite3", "file:store_whatsapp.db?_foreign_keys=on", dbLog) if err != nil { log.Fatalln(err) }