added the SendSMS func to the httpAccount service

This commit is contained in:
Alfred Kamanda 2025-03-06 09:06:45 +03:00
parent 6c4702e2ba
commit 4a5de68a8c
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703
2 changed files with 32 additions and 0 deletions

View File

@ -17,4 +17,5 @@ type AccountService interface {
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error)
RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error)
SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.TokenTransferResponse, error)
}

View File

@ -248,6 +248,37 @@ func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string
return svc.RequestAlias(ctx, publicKey, hint)
}
// SendSMS calls the API to send out an SMS.
// Parameters:
// - inviterPhone: The user initiating the SMS.
// - inviteePhone: The number being invited to Sarafu.
func (as *HTTPAccountService) SendSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
var r models.SendSMSResponse
// Create request payload
payload := map[string]string{
"inviterPhone": inviterPhone,
"inviteePhone": inviteePhone,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return nil, err
}
// Create a new request
req, err := http.NewRequest("POST", config.SendSMSURL, bytes.NewBuffer(payloadBytes))
if err != nil {
return nil, err
}
_, err = doRequest(ctx, req, &r)
if err != nil {
return nil, err
}
return &r, nil
}
// TODO: remove eth-custodial api dependency
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
var okResponse api.OKResponse