-
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: wip pair code login 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 * feat: add api login with code * feat: add ui getting pair code * feat: add pair code * chore: update docs & text * feat: upgrade version * chore: update docs * feat: update image gallery * fix: show error message * chore: update repo * fix: some code improvement
- Loading branch information
1 parent
8e5b1da
commit 7eb1de0
Showing
16 changed files
with
327 additions
and
38 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
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,7 +1,7 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: WhatsApp API MultiDevice | ||
version: 4.1.0 | ||
version: 4.2.0 | ||
description: This API is used for sending whatsapp via API | ||
servers: | ||
- url: http://localhost:3000 | ||
|
@@ -36,6 +36,32 @@ paths: | |
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorInternalServer' | ||
/app/login-with-code: | ||
get: | ||
operationId: appLoginWithCode | ||
tags: | ||
- app | ||
summary: Login with pairing code | ||
parameters: | ||
- name: phone | ||
in: query | ||
schema: | ||
type: string | ||
example: '628912344551' | ||
description: Your phone number | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/LoginWithCodeResponse' | ||
'500': | ||
description: Internal Server Error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorInternalServer' | ||
/app/logout: | ||
get: | ||
operationId: appLogout | ||
|
@@ -1241,6 +1267,21 @@ components: | |
device: | ||
type: string | ||
example: '628960561XXX.0:[email protected]' | ||
LoginWithCodeResponse: | ||
type: object | ||
properties: | ||
code: | ||
type: string | ||
example: SUCCESS | ||
message: | ||
type: string | ||
example: Success | ||
results: | ||
type: object | ||
properties: | ||
pair_code: | ||
type: string | ||
example: ABCD-1234 | ||
LoginResponse: | ||
type: object | ||
properties: | ||
|
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
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
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
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
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,21 @@ | ||
package validations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error" | ||
validation "github.com/go-ozzo/ozzo-validation/v4" | ||
"regexp" | ||
) | ||
|
||
func ValidateLoginWithCode(ctx context.Context, phoneNumber string) error { | ||
// Combine validations using a single ValidateWithContext call | ||
err := validation.ValidateWithContext(ctx, &phoneNumber, | ||
validation.Required, | ||
validation.Match(regexp.MustCompile(`^\+?[0-9]{1,15}$`)), | ||
) | ||
if err != nil { | ||
return pkgError.ValidationError(fmt.Sprintf("phone_number(%s): %s", phoneNumber, err.Error())) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package validations | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestValidateLoginWithCode(t *testing.T) { | ||
type args struct { | ||
phoneNumber string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Phone with +", | ||
args: args{phoneNumber: "+6281234567890"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Phone without +", | ||
args: args{phoneNumber: "621234567890"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Phone with 0", | ||
args: args{phoneNumber: "081234567890"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Phone contains alphabet", | ||
args: args{phoneNumber: "+6281234567890a"}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Empty phone number", | ||
args: args{phoneNumber: ""}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Phone with special characters", | ||
args: args{phoneNumber: "+6281234567890!@#"}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Extremely long phone number", | ||
args: args{phoneNumber: "+62812345678901234567890"}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := ValidateLoginWithCode(context.Background(), tt.args.phoneNumber); (err != nil) != tt.wantErr { | ||
t.Errorf("ValidateLoginWithCode() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.