Skip to content

Commit

Permalink
This is working
Browse files Browse the repository at this point in the history
Needs to test thsi
  • Loading branch information
keyurboss committed Apr 10, 2024
1 parent 894875b commit ff5b09b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ __debug*
*.db

server.config.json
tmp
tmp
jwelly.whatsapp.config
2 changes: 2 additions & 0 deletions jwelly/jwelly.whatsapp.config.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http://127.0.0.1:4000/v1
true
22 changes: 21 additions & 1 deletion jwelly/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"slices"
"strings"
"time"

"github.com/rpsoftech/whatsapp-http-api/validator"
)

type JwellyWhatsappConfig struct {
ServerUrl string `json:"serverUrl"`
Token string `json:"token"`
DoNotWaitForResponse bool `json:"doNotWaitForResponse"`
}

Expand All @@ -35,6 +36,7 @@ func main() {
if _, err := os.Stat("./whatsapp.config"); err == nil {
// path/to/whatever exists
if res, err := os.ReadFile("./whatsapp.config"); err == nil {
config = ReadConfigFileAndReturnIt(FindAndReturnCurrentDir())
AfterWhatsappConfigFile(string(res))
}
} else if errors.Is(err, os.ErrNotExist) {
Expand All @@ -48,6 +50,24 @@ func main() {

AppendToOutPutFile(fmt.Sprintln(len(os.Args), os.Args))
}

func ReadConfigFileAndReturnIt(currentDir string) *JwellyWhatsappConfig {
configFilePAth := filepath.Join(currentDir, "jwelly.whatsapp.config")
dat, err := os.ReadFile(configFilePAth)
if err != nil {
panic(fmt.Errorf("failed to read config file: %w", err))
}
config := &JwellyWhatsappConfig{}
_, err = fmt.Sscanln(string(dat), &config.ServerUrl, &config.DoNotWaitForResponse)
if err != nil {
panic(fmt.Errorf("failed to parse config file: %w", err))
}
if errs := validator.Validator.Validate(config); len(errs) > 0 {
panic(fmt.Errorf("CONFIG_ERROR %#v", errs))
}
return config
}

func AfterWhatsappConfigFile(data string) {
// Check that config is not null
if config == nil {
Expand Down

0 comments on commit ff5b09b

Please sign in to comment.