Android Question sending text messages through message apps

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi

i have an app that send text messages from the user to his clients (not span - it send reports and reports links)
it is critical to send using the user's phone not any kind of bot or service

i currently manage to send using whatsapp & whatsapp for business (the user enters his client's phone and the app opens loaded with the message and needs to press send and then back to return to my app

i also send sms pretty much in the same way - and now i can do it directly as wanted thanks to @John Naylor who provided the link to the right code and @DonManfred who keeps the right pressure on my head so i don't go side ways :)

with telegram i didn't find a way to enter the receiver's phone so the user has to locate the client and send

my questions:

  1. is there a way to directly send without opening whatsapp and press send?
  2. is there a way that my app will automatically return without the user press back?
  3. is there a way to send using telegram as i do whatsapp - no need to search the receiver in telegram?
  4. is there a way to send using signal?
what i want to have is the user enters his client's phone, the text message is preloaded, choose the app he wants to send with and press send - that will be the optimum

a basic sample will be highly appreciated

thanks
 

John Naylor

Active Member
Licensed User
Longtime User
OK I will answer with a Signal example as I have done it with that but not the others. I assume they're very similar though.

The process is quite simple. Sign up for an API account here.

Then in your app you can send a message as follows...

B4X:
Private Sub SendPostRequest

    Dim job As HttpJob
    job.Initialize("Job1", Me)
  
    ' URL of the API
    Dim url As String = "https://api.melroselabs.com/signal/message"
  
    ' Create the payload as a JSON object
    Dim payload As Map
    payload.Initialize
    payload.Put("systemid", "[YourAPISystemIDHere]")
    payload.Put("password", "[YourAPIPasswordHere]")
    payload.Put("destination", "[DestinationPhoneNumberInInternationalFormat(No + Needed)]")
    payload.Put("text", "[Your message text]")
    payload.Put("scheduled", "2024-09-04T11:26:51.922Z")    'Skip this to send straight away
  
    ' Convert payload to JSON
    Dim json As JSONGenerator
    json.Initialize(payload)
    Dim payloadString As String = json.ToString
  
    ' Headers
    job.GetRequest.SetHeader("accept", "application/json")
    job.GetRequest.SetHeader("content-type", "application/json")
  
    ' Send POST request with JSON payload
    job.PostString(url, payloadString)
  
    ' Wait for the response
    Wait For (job) JobDone(job As HttpJob)
  
    If job.Success Then
        ' Print the response
        Log(job.GetString)
    Else
        Log("Error: " & job.ErrorMessage)
    End If
  
    job.Release
End Sub

The JSON payload will likely be slightly different for Telegram and WhatsApp but will be documented in their API files.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Isn´t Signal using Firebase Mesaging internally?
Why not use FirebaseMessaging directly instead of Signal?
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
Isn´t Signal using Firebase Mesaging internally?
Why not use FirebaseMessaging directly instead of Signal?
Yes it does but Signal enforces privacy further than Firebase. Plus if the reciever of the message is using Signal, Firebase obviously cannot send directly to it.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
When you said "i also send sms pretty much in the same way - and now i can do it directly as wanted"..... are you sending the SMS without the user having to click "Send" in their SMS app?

If so, please post the link to the code that does this :)
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
When you said "i also send sms pretty much in the same way - and now i can do it directly as wanted"..... are you sending the SMS without the user having to click "Send" in their SMS app?

If so, please post the link to the code that does this :)
YES!!!
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
When you said "i also send sms pretty much in the same way - and now i can do it directly as wanted"..... are you sending the SMS without the user having to click "Send" in their SMS app?

If so, please post the link to the code that does this :)
See here.

I use it a lot in apps where I need to confirm the users phone number. I have the app generate a code, send it via SMS (to the supplied number) and set a timer for expiry. Then get the user to type the code into the app.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
OK I will answer with a Signal example as I have done it with that but not the others. I assume they're very similar though.

The process is quite simple. Sign up for an API account here.

Then in your app you can send a message as follows...

B4X:
Private Sub SendPostRequest

    Dim job As HttpJob
    job.Initialize("Job1", Me)
 
    ' URL of the API
    Dim url As String = "https://api.melroselabs.com/signal/message"
 
    ' Create the payload as a JSON object
    Dim payload As Map
    payload.Initialize
    payload.Put("systemid", "[YourAPISystemIDHere]")
    payload.Put("password", "[YourAPIPasswordHere]")
    payload.Put("destination", "[DestinationPhoneNumberInInternationalFormat(No + Needed)]")
    payload.Put("text", "[Your message text]")
    payload.Put("scheduled", "2024-09-04T11:26:51.922Z")    'Skip this to send straight away
 
    ' Convert payload to JSON
    Dim json As JSONGenerator
    json.Initialize(payload)
    Dim payloadString As String = json.ToString
 
    ' Headers
    job.GetRequest.SetHeader("accept", "application/json")
    job.GetRequest.SetHeader("content-type", "application/json")
 
    ' Send POST request with JSON payload
    job.PostString(url, payloadString)
 
    ' Wait for the response
    Wait For (job) JobDone(job As HttpJob)
 
    If job.Success Then
        ' Print the response
        Log(job.GetString)
    Else
        Log("Error: " & job.ErrorMessage)
    End If
 
    job.Release
End Sub

The JSON payload will likely be slightly different for Telegram and WhatsApp but will be documented in their API files.
i'm trying to register to this api site
it goes all the way but then just freezes so i can't proceed
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
i'm trying to register to this api site
it goes all the way but then just freezes so i can't proceed
Freezes? When I signed up it just showed a confirmation that details would be sent to my email address (which can take a short while). Maybe try a different browser.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Freezes? When I signed up it just showed a confirmation that details would be sent to my email address (which can take a short while). Maybe try a different browser.
i use chrome
i register - provide mail & password
they sent email with 4 digits code
i entered the code & checked "i agree"
went to sleep....
 
Upvote 0
Top