Skip to content

Commit

Permalink
change endpoint for send message
Browse files Browse the repository at this point in the history
  • Loading branch information
NandaRusfikri committed Oct 10, 2023
1 parent 3c4454d commit 7bd19ed
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea
.env
crm-tickets
examplestore.db
store_whatsapp.db
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Binary file modified README.md
Binary file not shown.
Binary file removed go-whatsapp
Binary file not shown.
18 changes: 12 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})
Expand All @@ -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{}) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 7bd19ed

Please sign in to comment.