-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding build files and basic working send text message
- Loading branch information
abansal88
committed
Mar 29, 2020
1 parent
dcc0170
commit 9341007
Showing
5 changed files
with
110 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOFMT=$(GOCMD) fmt | ||
GOLIST=$(GOCMD) list | ||
GOVET=$(GOCMD) vet | ||
|
||
.PHONY: all | ||
all: fmt vet lint build | ||
|
||
.PHONY: build | ||
build: | ||
$(GOBUILD) -o whatsapp-cli -v | ||
|
||
.PHONY: fmt | ||
fmt: | ||
$(GOFMT) ./... | ||
|
||
.PHONY: lint | ||
fmt: | ||
$(GOLIST) ./... | grep -v /vendor/ | xargs -L1 golint | ||
|
||
.PHONY: vet | ||
vet: | ||
$(GOVET) ./... | ||
|
||
.PHONY: clean | ||
clean: | ||
rm whatsapp-cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
package executors | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Rhymen/go-whatsapp" | ||
) | ||
|
||
// SendText sends the provided text message to the receipient. | ||
func SendText(text, reciever string) error { | ||
wac, err := whatsapp.NewConn(5 * time.Second) | ||
if err != nil { | ||
return fmt.Errorf("error creating connection: %v\n", err) | ||
} | ||
|
||
err = LoginWithConnection(wac) | ||
if err != nil { | ||
return fmt.Errorf("error logging in: %v\n", err) | ||
} | ||
|
||
<-time.After(3 * time.Second) | ||
|
||
text += "\n sent using github.com/abansal4032/go-whatsapp-cli" | ||
msg := whatsapp.TextMessage{ | ||
Info: whatsapp.MessageInfo{ | ||
RemoteJid: reciever + "@s.whatsapp.net", | ||
}, | ||
Text: text, | ||
} | ||
|
||
msgID, err := wac.Send(msg) | ||
if err != nil { | ||
return fmt.Errorf("error sending message: %v", err) | ||
} | ||
|
||
fmt.Printf("successfully sent, messaageID : %v\n", msgID) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/abansal4032/go-whatsapp-cli/executors" | ||
"github.com/abansal4032/go-whatsapp-cli/utils" | ||
) | ||
|
||
func commandUsage(err error) { | ||
func commandUsage(err error, f *flag.FlagSet) { | ||
fmt.Println("correct command usage is described below:") | ||
f.PrintDefaults() | ||
} | ||
|
||
func errorHandler(err error) { | ||
// TODO : graceful error handling here | ||
if err != nil { | ||
fmt.Println("correct command usage is described below:") | ||
flag.PrintDefaults() | ||
fmt.Printf("flow errored out : %v\n", err.Error()) | ||
} | ||
} | ||
|
||
func main() { | ||
sendTextCmd := flag.NewFlagSet("sendText", flag.ExitOnError) | ||
var err error | ||
defer func() { | ||
commandUsage(err) | ||
errorHandler(err) | ||
}() | ||
|
||
switch os.Args[1] { | ||
|
||
case "login": | ||
if err = executors.Login(); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
case "logout": | ||
if err = executors.Logout(); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
case "sendText": | ||
//var args *utils.SendArgs | ||
_, err = utils.ParseSendArgs(sendTextCmd, os.Args[2:]) | ||
var args *utils.SendArgs | ||
args, err = utils.ParseSendArgs(sendTextCmd, os.Args[2:]) | ||
if err != nil { | ||
fmt.Println(err) | ||
commandUsage(err, sendTextCmd) | ||
return | ||
} | ||
/*if err = executors.SendText(args); err != nil { | ||
fmt.Println(err) | ||
if err = executors.SendText(args.GetContent(), args.GetReciever()); err != nil { | ||
return | ||
}*/ | ||
} | ||
|
||
default: | ||
fmt.Println("wrong command provided. please see below for the list of permitted actions") | ||
flag.PrintDefaults() | ||
// TODO : add a list of all permitted actions | ||
err = fmt.Errorf("wrong command provided. please see below for the list of permitted actions") | ||
return | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters