added the SendSMS func to the httpAccount service
This commit is contained in:
parent
6c4702e2ba
commit
4a5de68a8c
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user