I am trying to implement a method to send SMS from XDATA/Sphinx server, using Spryng API services.
TTMSFNCCloudSMS works fine, but only on visual form VCL or FMX. Is there a way to do this on a server (Windows service)? Will there be a future adaptation for Sphinx?
Thank you
Right now, it's not possible to do this via a service, we'll investigate the possibilities.
Hi
I finally came up with a solution that works for me, and could help others. I use it successfully on TMS Sphinx server. There is probably a more elegant way but I created a form to drop the TMSFNCCloudSMS component on it. And I made a call via a class function:
class function TCloudSmsFrm.SendSMS(ASender: TComponent; const AKey, ATo, AMessage: string;
var AResultMessage: string): Boolean;
var
LForm: TCloudSmsFrm;
begin
LForm := TCloudSmsFrm.Create(ASender);
try
LForm.Init(AKey);
LForm.Send(ATo, AMessage);
while not LForm.Finished do
begin
Application.ProcessMessages; Sleep(500);
end;
Result := LForm.Statut;
AResultMessage := ResultString;
finally
LForm.Free;
end;
end;
procedure TCloudSmsFrm.Init(const AKey: string);
begin
Assert(not AKey.IsEmpty, 'Missing secure key');
FStatut := False; FResultString := ''; FFinished := False;
TMSFNCCloudSMS1.Service := cssSpryng;
TMSFNCCloudSMS1.APIKey := AKey;
end;
procedure TCloudSmsFrm.Send(const ATo, AMessage: string);
begin
Assert(not ATo.IsEmpty, 'Missing recipient number');
Assert(not AMessage.IsEmpty, 'Missing SMS message');
FFinished := False;
TMSFNCCloudSMS1.SendCloudSMS(cSMS_SENDER, ATo, AMessage);
end;
procedure TCloudSmsFrm.TMSFNCCloudSMS1SendCloudSMS(Sender: TObject; const ARequest:
TTMSFNCCloudSMSRequest; const ARequestResult:
TTMSFNCCloudBaseRequestResult);
begin
FStatut := ARequestResult.Success;
FResultString := ARequestResult.ResultString;
FFinished := True;
end;
and I call it as a separate module like:
var LErrMessage: string;
if TCloudSmsFrm.SendSMS(Self, 'SMSTOKEN', '+32499999999', 'Your personal token is 369852'), LErrMessage) then
ShowMessage('Message sent successfully')
else
ShowMessage(LErrMessage);
You could also just create TTMSFNCCloudSMS.Create(nil), because the owner is actually not required.
@Pieter OK, thank you