Skip to content

Commit

Permalink
Verify caller ID for outbound voice calls - Go SDK changes (#187)
Browse files Browse the repository at this point in the history
* Verify caller ID for outbound voice calls - Go SDK changes

* fixed response structure

* added versions
  • Loading branch information
Abinaya-Shunmugavel authored Oct 18, 2023
1 parent 5428c02 commit d6cff0d
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [7.39.0](https://github.com/plivo/plivo-go/tree/v7.39.0) (2023-10-18)
**Feature - Verify CallerID**
- Added Initiate and Verify VerifyCallerID API
- Added Update, Delete, Get and List verified CallerIDs API

## [7.38.0](https://github.com/plivo/plivo-go/tree/v7.38.0) (2023-10-16)
**Feature - Campaign API Enhancements & New API for Importing Partner Campaigns**
- Import Partner Campaign API
Expand Down
4 changes: 2 additions & 2 deletions baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/google/go-querystring/query"
)

const sdkVersion = "7.38.0"
const sdkVersion = "7.39.0"

const lookupBaseUrl = "lookup.plivo.com"

Expand Down Expand Up @@ -72,7 +72,7 @@ func (client *BaseClient) NewRequest(method string, params interface{}, baseRequ

requestUrl.RawQuery = values.Encode()
} else {
if reflect.ValueOf(params).Kind().String() != "map" {
if reflect.ValueOf(params).Kind().String() != "map" && params != nil {
if err = json.NewEncoder(buffer).Encode(params); err != nil {
return
}
Expand Down
10 changes: 10 additions & 0 deletions fixtures/getVerifiedCallerIDResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"alias": "test",
"api_id": "ee7c3cb1-c921-42c9-832b-950fb8344b9b",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"subaccount": "",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}
5 changes: 5 additions & 0 deletions fixtures/initiateVerifyResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"api_id": "2a5e81d7-deb3-46cd-ac34-c05ca9139b6f",
"message": "Verification code is sent to number +919768368717 which is valid for 15 minutes",
"verification_uuid": "407796a6-1f3e-4607-a9d9-5a5376b59a7b"
}
52 changes: 52 additions & 0 deletions fixtures/listVerifiedCallerIDResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"api_id": "3b21c7d7-09f7-489b-b753-659814a676bf",
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 4
},
"objects": [
{
"alias": "abhishek",
"country": "IN",
"created_at": "2023-09-25T14:40:38.68729Z",
"modified_at": "2023-09-25T14:40:38.68729Z",
"phone_number": "+919653244280",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919653244280",
"subaccount": "",
"verification_uuid": "01be6b07-b106-46e2-8dfc-096d8e22cc0e"
},
{
"alias": "abhishek",
"country": "IN",
"created_at": "2023-09-25T13:10:39.968133Z",
"modified_at": "2023-09-25T13:10:39.968133Z",
"phone_number": "+919768368717",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368717",
"subaccount": "",
"verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4"
},
{
"alias": "test",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368718",
"subaccount": "",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
},
{
"alias": "Test2",
"country": "",
"created_at": "2023-08-30T07:47:43.87171Z",
"modified_at": "2023-08-30T07:47:43.87171Z",
"phone_number": "+917691021365",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/917691021365",
"subaccount": "SAMTU0Y2FKNGETYZDKNI",
"verification_uuid": "20265c57-2d8e-46fe-8fa8-e8ab4ee58a8c"
}
]
}
10 changes: 10 additions & 0 deletions fixtures/updateVerifiedCallerIDResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"alias": "testAbhishek",
"api_id": "6b143cb3-9c8a-42ad-b6b7-412ebd5c60a9",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"subaccount": "SAMTU0Y2FKNGETYZDKNI",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}
9 changes: 9 additions & 0 deletions fixtures/verifyCallerIDResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"alias": "abhishek",
"api_id": "584a97aa-ca1d-44f2-9dd3-e58fbacd6649",
"channel": "call",
"country": "IN",
"created_at": "2023-09-25T13:10:39.968133341Z",
"phone_number": "+919768368717",
"verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4"
}
10 changes: 5 additions & 5 deletions maskingsession_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestCallService_CreateMaskingSession(t *testing.T) {
func TestMaskingSessionService_CreateMaskingSession(t *testing.T) {
expectResponse("createMaskingSessionResponse.json", 200)

if _, err := client.MaskingSession.CreateMaskingSession(CreateMaskingSessionParams{}); err != nil {
Expand All @@ -24,7 +24,7 @@ func TestCallService_CreateMaskingSession(t *testing.T) {
assertRequest(t, "POST", "Masking/Session")
}

func TestCallService_DeleteMaskingSession(t *testing.T) {
func TestMaskingSessionService_DeleteMaskingSession(t *testing.T) {
expectResponse("deleteMaskingSessionResponse.json", 204)
SessionUuid := "15e4256c-be01-475c-9a69-95cf65bbed71"

Expand All @@ -44,7 +44,7 @@ func TestCallService_DeleteMaskingSession(t *testing.T) {
assertRequest(t, "DELETE", "Masking/Session/%s", SessionUuid)
}

func TestCallService_GetMaskingSession(t *testing.T) {
func TestMaskingSessionService_GetMaskingSession(t *testing.T) {
expectResponse("getMaskingSessionResponse.json", 200)
SessionUuid := "15e4256c-be01-475c-9a69-95cf65bbed71"

Expand All @@ -64,7 +64,7 @@ func TestCallService_GetMaskingSession(t *testing.T) {
assertRequest(t, "GET", "Masking/Session/%s", SessionUuid)
}

func TestCallService_updateMaskingSession(t *testing.T) {
func TestMaskingSessionService_updateMaskingSession(t *testing.T) {
expectResponse("updateMaskingSessionResponse.json", 204)
SessionUuid := "15e4256c-be01-475c-9a69-95cf65bbed71"

Expand All @@ -84,7 +84,7 @@ func TestCallService_updateMaskingSession(t *testing.T) {
assertRequest(t, "POST", "Masking/Session/%s", SessionUuid)
}

func TestCallService_ListMaskingSession(t *testing.T) {
func TestMaskingSessionService_ListMaskingSession(t *testing.T) {
expectResponse("listMaskingSessionResponse.json", 204)

if _, err := client.MaskingSession.ListMaskingSession(ListSessionFilterParams{}); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions plivoclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Client struct {
Campaign *CampaignService
MaskingSession *MaskingSessionService
VerifySession *VerifyService
VerifyCallerId *VerifyCallerIdService
}

/*
Expand Down Expand Up @@ -120,6 +121,7 @@ func NewClient(authId, authToken string, options *ClientOptions) (client *Client
client.Profile = &ProfileService{client: client}
client.MaskingSession = &MaskingSessionService{client: client}
client.VerifySession = &VerifyService{client: client}
client.VerifyCallerId = &VerifyCallerIdService{client: client}
return
}

Expand Down
138 changes: 138 additions & 0 deletions verify_callerid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package plivo

import (
"time"
)

type VerifyCallerIdService struct {
client *Client
}

type InitiateVerify struct {
PhoneNumber string `json:"phone_number"`
Alias string `json:"alias"`
Channel string `json:"channel"`
Country string `json:"country"`
SubAccount string `json:"subaccount"`
AccountID int64 `json:"account_id"`
AuthID string `json:"auth_id"`
AuthToken string `json:"auth_token"`
}

type InitiateVerifyResponse struct {
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
Message string `json:"message,omitempty" url:"message,omitempty"`
VerificationUUID string `json:"verification_uuid,omitempty" url:"verification_uuid,omitempty"`
}

type ListVerifiedCallerIdParams struct {
Country string `json:"country,omitempty" url:"country,omitempty"`
SubAccount string `json:"subaccount,omitempty" url:"subaccount,omitempty"`
Alias string `json:"alias,omitempty" url:"alias,omitempty"`
Limit int64 `json:"limit,omitempty" url:"limit,omitempty"`
Offset int64 `json:"offset,omitempty" url:"offset,omitempty"`
}

type VerifyResponse struct {
Alias string `json:"alias,omitempty"`
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
Channel string `json:"channel"`
Country string `json:"country"`
CreatedAt time.Time `json:"created_at"`
PhoneNumber string `json:"phone_number"`
VerificationUUID string `json:"verification_uuid"`
SubAccount string `json:"subaccount,omitempty"`
}

type UpdateVerifiedCallerIDParams struct {
Alias string `json:"alias,omitempty"`
SubAccount string `json:"subaccount,omitempty"`
}

type GetVerifyResponse struct {
Alias string `json:"alias,omitempty"`
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
Country string `json:"country"`
CreatedAt time.Time `json:"created_at"`
ModifiedAt time.Time `json:"modified_at"`
PhoneNumber string `json:"phone_number"`
SubAccount string `json:"subaccount,omitempty" url:"subaccount,omitempty"`
VerificationUUID string `json:"verification_uuid"`
}

type ListVerifyResponse struct {
Alias string `json:"alias,omitempty"`
Country string `json:"country"`
CreatedAt time.Time `json:"created_at"`
ModifiedAt time.Time `json:"modified_at"`
PhoneNumber string `json:"phone_number"`
ResourceUri string `json:"resource_uri,omitempty"`
SubAccount string `json:"subaccount,omitempty"`
VerificationUUID string `json:"verification_uuid"`
}

type ListVerifiedCallerIDResponse struct {
ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
Meta Meta `json:"meta" url:"meta"`
Objects []ListVerifyResponse `json:"objects" url:"objects"`
}

func (service *VerifyCallerIdService) InitiateVerify(params InitiateVerify) (response *InitiateVerifyResponse, err error) {
req, err := service.client.NewRequest("POST", params, "VerifiedCallerId")
if err != nil {
return
}
response = &InitiateVerifyResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}

func (service *VerifyCallerIdService) VerifyCallerID(verificationUuid string, otp string) (response *VerifyResponse, err error) {
req, err := service.client.NewRequest("POST", map[string]string{"otp": otp}, "VerifiedCallerId/Verification/%s", verificationUuid)
if err != nil {
return
}
response = &VerifyResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}

func (service *VerifyCallerIdService) DeleteVerifiedCallerID(phoneNumber string) (err error) {
req, err := service.client.NewRequest("DELETE", nil, "VerifiedCallerId/%s", phoneNumber)
if err != nil {
return
}
err = service.client.ExecuteRequest(req, nil, isVoiceRequest())

return
}

func (service *VerifyCallerIdService) UpdateVerifiedCallerID(phoneNumber string, params UpdateVerifiedCallerIDParams) (response *GetVerifyResponse, err error) {
req, err := service.client.NewRequest("POST", params, "VerifiedCallerId/%s", phoneNumber)
if err != nil {
return
}
response = &GetVerifyResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}

func (service *VerifyCallerIdService) GetVerifiedCallerID(phoneNumber string) (response *GetVerifyResponse, err error) {
req, err := service.client.NewRequest("GET", nil, "VerifiedCallerId/%s", phoneNumber)
if err != nil {
return
}
response = &GetVerifyResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}

func (service *VerifyCallerIdService) ListVerifiedCallerID(params ListVerifiedCallerIdParams) (response *ListVerifiedCallerIDResponse, err error) {
req, err := service.client.NewRequest("GET", params, "VerifiedCallerId")
if err != nil {
return
}
response = &ListVerifiedCallerIDResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}
Loading

0 comments on commit d6cff0d

Please sign in to comment.