Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

blackberry.invoke.invoke + Text Messaging

[ Edited ]

Hi

we need to implement SMS functionality in wekworks application. I have found following link to do that

http://origin-developer.blackberry.com/html5/documentation/text_messages.html

I have tried with the following code

blackberry.invoke.invoke({

        target: "sys.pim.text_messaging.composer",

        action: "bb.action.COMPOSE",

        type:   "application/text_messaging",

                                data:   "to : 150 , body : 'ABCD', send:true"

    }, onSuccess, onError);

 

But by the above code application unable to invoke text message in BB10

 

Can anyone share working code? I need to use all three parameter

"

 

Attribute

Value

Target ID

sys.pim.text_messaging.composer

Action

bb.action.COMPOSE

MIME type

application/text_messaging

Data must be PPS-encoded and contain the following fields:

Field

Description

to

This field represents the list of recipients in JSON format.

body

This field represents the text contained in the body of the text message.

send

This field should be set as a Boolean value. If the value is set true, the message is sent right away. If the value is false, the composer remains on the screen.

 

"

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: blackberry.invoke.invoke + Text Messaging

[ Edited ]

This is a bit tricky since you need to PPS encode the data. Good job on reading the documentation, even thought it is still a tricky task to know what to do without internal knowledge. We wrapped a few cards for you, but this is one we didn't have time to do yet. Here is how you can do it:

 

1. Your invoke request is great, you don't need the type attribute, it can be omitted since the card is expecting pps encoded data.

 

2.  You should write a helper routing to encode the data for you. Here is one that might help:

 

var ppsEncode = function (obj) {
        var data = '',
            name,
            value;
        for (name in obj) {
            data += name + ':';
            value = obj[name];
            if (typeof value === 'string') {
                data += ':' + value;
            } else if (typeof value === 'number') {
                data += 'n:' + value;
            } else if (typeof value === 'boolean') {
                data += 'b:' + value;
            } else if (typeof value === 'object') {
                data += 'json:' + JSON.stringify(value);
            }
            data += '\n';
        }
        return data;
    }

This function is by no means complete, but should be sufficient for your purposes.

 

3. When executing your invoke request now do something like this:

 

blackberry.invoke.invoke({
        target: "sys.pim.text_messaging.composer",
        action: "bb.action.COMPOSE",
        data : ppsEncode({"to":["6475243431"], "body":"Something something...", "send":"false"}),
    }, onSuccess, onError);

The to field is actually an array of recipients, this usually trips people up, as well the value send should be false by default unless you want the message to be sent right as the card open without user intervention. Let me know if that helps Smiley Happy.

@erikjohnzon
erjohnson@blackberry.com
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: blackberry.invoke.invoke + Text Messaging

We are unable to close the window once the sms has sent i.e window should automatically close after successfully sent the sms.

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: blackberry.invoke.invoke + Text Messaging

This was not in the original question. Stay tuned.

@erikjohnzon
erjohnson@blackberry.com
Trusted Contributor
Posts: 118
Registered: ‎03-06-2013
My Device: Blackberry Z10
My Carrier: Airtel

Re: blackberry.invoke.invoke + Text Messaging

this worked for me, but how to do the background sending of sms, instead of invoking composer.

--------
- If a post contains the solution to the problem, please click "Accept as Solution"
- If a post contains helpful content, please give it a "Thumbs Up"

developer.blackberry.com
@BlackBerryDev
Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: blackberry.invoke.invoke + Text Messaging

As far as I can see this will require a native extension. You will access the PIM service and be using the following class 

 

https://developer.blackberry.com/cascades/reference/bb__pim__message__smstransport.html.

 

This is a Cascades API class.

 

This will allow you to programatically send an SMS message to the destination of your choice. The sample native extension template has been provided by Dev Rel here:

 

https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10/Template

@erikjohnzon
erjohnson@blackberry.com
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: blackberry.invoke.invoke + Text Messaging

  1. I have also tried this approach also. But I get compilation error  when Introduce the cascades API

Following is the original post

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Custom-BB-Webworks-Phonegap-plug...

 

astanley” as  replied

“You cannot use Cascades code/libraries inside of a WebWorks extension.  You can only use native C/C++ or Qt code.”

 

Any HELP

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Retired
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: blackberry.invoke.invoke + Text Messaging

My mistake. This looks like a platform limitation of using WebWorks. You may be able to get more visibility in the Native SDK. I have not found a reference to the messaging service in the documentation thus far. Sorry I couldn't be of more help.

@erikjohnzon
erjohnson@blackberry.com
Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: blackberry.invoke.invoke + Text Messaging

That means there is no way to implement sms in the background.

 

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: blackberry.invoke.invoke + Text Messaging

Did I miss the part where you tell us what device this was for?  Is it for BB10?  Or for OS6+ ?

 

I used code in my webworks app on an OS6+ device which works great in the background.  Something like:

 

    try {

        blackberry.message.sms.send("Hi, my totals for " + returnMonth() + " are: " + document.getElementById('fsTotals_current').innerHTML + ' - Regards, ' + from, sms_to);

        alert("SMS to " + sms_to + " has been sent.");

    } catch (e) {
        alert("There was a problem smsing time records! " + e);
    }

 Obviously you'd need to imagine that all those variables are set  but the key part is:

 

blackberry.message.sms.send

Which needs:

 

  <feature id="blackberry.message" />
  <feature id="blackberry.message.sms" />

in your XML config file.

If it helped you, click like. Smiley Happy