Skip to content

Commit

Permalink
feat: wip pair code login
Browse files Browse the repository at this point in the history
feat(app): add LoginWithCode method to IAppService interface for handling phone number login
feat(app): implement LoginWithCode method in App struct to handle phone number login logic
feat(app): implement LoginWithCode method in serviceApp to pair phone number with WhatsApp client
  • Loading branch information
aldinokemal committed Jul 13, 2024
1 parent 8e5b1da commit d6fd8ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/domains/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type IAppService interface {
Login(ctx context.Context) (response LoginResponse, err error)
LoginWithCode(ctx context.Context, phoneNumber string) (err error)
Logout(ctx context.Context) (err error)
Reconnect(ctx context.Context) (err error)
FirstDevice(ctx context.Context) (response DevicesResponse, err error)
Expand Down
14 changes: 14 additions & 0 deletions src/internal/rest/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type App struct {
func InitRestApp(app *fiber.App, service domainApp.IAppService) App {
rest := App{Service: service}
app.Get("/app/login", rest.Login)
app.Get("/app/login-with-code", rest.LoginWithCode)
app.Get("/app/logout", rest.Logout)
app.Get("/app/reconnect", rest.Reconnect)
app.Get("/app/devices", rest.Devices)
Expand All @@ -36,6 +37,19 @@ func (handler *App) Login(c *fiber.Ctx) error {
})
}

func (handler *App) LoginWithCode(c *fiber.Ctx) error {
err := handler.Service.LoginWithCode(c.UserContext(), c.Query("phone"))
utils.PanicIfNeeded(err)

return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: "Login with code success",
Results: nil,
})

}

func (handler *App) Logout(c *fiber.Ctx) error {
err := handler.Service.Logout(c.UserContext())
utils.PanicIfNeeded(err)
Expand Down
11 changes: 11 additions & 0 deletions src/services/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ func (service serviceApp) Login(_ context.Context) (response domainApp.LoginResp
return response, nil
}

func (service serviceApp) LoginWithCode(ctx context.Context, phoneNumber string) (err error) {
phone, err := service.WaCli.PairPhone(phoneNumber, true, whatsmeow.PairClientChrome, "Chrome (Linux)")
if err != nil {
return err
}

logrus.Info("Phone: ", phone)

return nil
}

func (service serviceApp) Logout(_ context.Context) (err error) {
// delete history
files, err := filepath.Glob(fmt.Sprintf("./%s/history-*", config.PathStorages))
Expand Down

0 comments on commit d6fd8ee

Please sign in to comment.