• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
March 29, 2024, 08:44:06 am

News:

SMF - Just Installed!


Auto Reply Message

Started by emka, October 04, 2019, 04:22:29 am

Previous topic - Next topic

emka

Hello,

is there a good scenario for logic that I do this. I made the application automatically reply to every message received. I do it in the event as in the code I included below.

procedure TFrmMessage.nrGsm1SmsReceived(Sender: TObject; aMem: String;
  idSms: Integer; aSms: TnrPduSms);
begin
  if aMem <> ''
    then ListBox1.Items.Add('Sms is received "' + aMem+'",'+ IntToStr(idSms))
    else ListBox1.Items.Add('Sms is received ');
  if aSms <> nil then begin
    if aSms.Report then
      ListBox1.Items.Add(aSms.ReportText + ' ' + DateTimeToStr(aSms.ReportDateTime))
    else
    begin
      ListBox1.Items.Add('SMS: From: ' + aSms.Phone + ' text: '+ aSms.Text);
      ReplyMessage(asms.Phone,aSms.Text);
    end;
  end;
  ListBox1.TopIndex := ListBox1.Count - 1;
  ListBox1.ItemIndex := ListBox1.Count - 1;
end;

procedure TFrmMessage.ReplyMessage(aPhone,aText: string);
begin
  TAnonymousThread.Execute(
      procedure
      begin
nrGSm1.SmsSend(aPhone, 'Thanks You For Your Confirm.', chConfirm.Checked);
      end
    ).OnException(
      procedure(aException : Exception)
      begin
        ListBox1.Items.Add(aException.Message);
      end
    ).OnTerminate(
      procedure
      begin
        ListBox1.Items.Add('Sent');
      end
    ).Start;
end;

I have a problem if there are many incoming message traffic, and some messages will not be answered by the application.

Thanks