Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No example for sms send/receive #113

Open
t-oster opened this issue May 31, 2022 · 2 comments
Open

No example for sms send/receive #113

t-oster opened this issue May 31, 2022 · 2 comments

Comments

@t-oster
Copy link

t-oster commented May 31, 2022

Hi,
Nice app. Unfortunately I cannot find any information regarding the SMS API. I want to build a simple SMS to MQTT gateway (bidirectional), which should be very easy with Phonk. Can you point me to the docs or the sources with the SMS functionality?

@polhomarkho
Copy link
Contributor

Hi!

The SMS functions are defined here phonk_apprunner/src/main/java/io/phonk/runner/apprunner/api/PDevice.java: device.onSmsReceived() and device.smsSend().
Here is a small example that sends and receives a SMS. The phone number is asked when running:

/*	
 *  Description Send and receive a SMS
 *  by Paul-Emile Sublet <[email protected]>
 */

ui.addTitle(app.name);

var phoneNumber;

const receivedSmsDetails = ui.addText(0, 0, 1, 0.5);
ui.popup()
  .title('Enter the phone number to send an SMS to')
  .ok('ok')
  .input('phone number')
  .onAction(function(phoneNumberInput) {
    phoneNumber = phoneNumberInput.answer;
  })
  .show();

// these methods are defined in phonk_apprunner/src/main/java/io/phonk/runner/apprunner/api/PDevice.java
device.onSmsReceived(function(sms) {
  receivedSmsDetails.text('from: ' + sms.from + "\n" + 'message: ' + sms.message);
});

ui.addButton('send sms', 0, 0.5, 1, 0.5)
  .onClick(function() {
    device.smsSend(phoneNumber, 'hello world!');
  });

@polhomarkho
Copy link
Contributor

Here is the PR adding this example: #119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants