Pushwoosh, how do I send 'open app' push notifications with custom data via the API? - react-native

I having trouble send a Pushwoosh notification using the API that matches what I can do in the web interface.
In the web interface, I navigate to the Action tab and select 'Open App' and enter custom json in the data field. This sends a notification that when clicked, triggers an even in my app and passes in custom data.
I have tried to recreate this using the createmessage API by passing in custom data. Using the Ruby client API I run
Pushwoosh.notify_devices("test", device_ids, { data: { foo: 1 } }). This triggers a push but when the user taps on the push notification it opens the app but does not pass any data or call any of the callbacks in my app when the app opens.
Am I using the wrong API or missing parameters?

Do you use "data" parameter in createMessage?
It will be passed as "u" parameter in the push payload.
"data": {"key":"value"}, // JSON string or JSON object, will be passed as "u" parameter in the payload (converted to JSON string)
If you want to modify the payload at any level you can use "ios_root_params"/"android_root_params" which is a JSON object and will be merged at the root level of the push payload.

Related

How can we filter the options of an entity select component in the app config?

We have an app and we would like to configure it to send out emails. On app activation a mail template type and a default mail template are created. However in the configuration we would like to be able to select which mail template we should send out. Our config.xml looks contains the following:
<component name="sw-entity-single-select">
<name>customerMailTemplate</name>
<entity>mail_template</entity>
<label>Choose which mail template to be sent to customers on reservation</label>
<labelProperty>description</labelProperty>
<placeholder>Select mail template</placeholder>
</component>
Our question has 2 parts:
Given that not all mail templates have a description, is there a way how we can include Type + description as labels? similar to the mail templates overview in the admin settings.
We would like to filter this list to only show mail templates of a certain type. I see that this component takes a criteria object but we could only transfer strings from the xml file to the component. Would this be possible?
Having a plugin would allow us to create custom components and add them in the admin, but I don't see how we could do this from an app. If the above are not possible is there a way to create a custom vue component from an app?
Unfortunately neither of those things are possible with apps as of today.
The component has a slot to override the label but since you can't access the template directly with apps, you can only define a single property for the label.
While the component does take a criteria, the config.xml schema is not prepared to take and pass a criteria to the component.
If this is a must-have you could go the route of adding a custom module for you app. This is essentially just an iframe with a source to a page you're hosting. On that page you'd have to build a custom select dropdown. To feed the dropdown with data you request the admin api (with the credentials you received in the app registration process). That's also when you can make use of the criteria filters.
POST /api/search/mail-template
{
"associations": {
"mailTemplateType": []
},
"filters": [
{
"type": "equals",
"field": "mailTemplateType.technicalName",
"value": "order_confirmation_mail"
}
]
}
With the data you received from that endpoint you could then also freely set the labels as you like.
Once the user made a selection you can then either save the selection on your app server or send it back to the admin api, e.g. for storing it in the plugin config.
POST /api/_action/system-config
{
"MyApp.config.customerMailTemplate": "cc4996d68d22421081285fe957f85ec7"
}

How can I test the data in the request that is sent during cypress test?

I have a Vue application that is using mongodb and flask for the back-end. I am trying to test the code as follows.
There is a form as you can see from the image above. When I enter the URL's, tokens, password, ssh, and project name, and click Create button, I add them to an object and send them to the database in a request.
I want to write these values in Cypress.js (this part is done), and click the create button. After clicking create button I want to test the data that is sent as request. How can I reach the body in the request in cypress?
You can use cy.intercept() to look at outbound requests. Request object documentation here.
cy.intercept('/some/url', (req) => {
// whatever you need to do with the request object
// for example, validating the request body has a name field
expect(req.body.name).to.equal('My Body Object Name');
// req.continue() tells the request to continue!
req.continue()
});

Proper way to send FCM device token to a webview

I have a webapp built on Laravel that is to be displayed on a mobile app (both android and ios, which are being built using React Native) via WebView.
I managed to use evollu/react-native-fcm to generate the token.
My question is: what is the proper way to send this token to the WebView, so my webapp can relate it to a user and store it on the database?
My first idea was to pass it along to the URL being called by the WebView as a GET parameter, but the parameter always come blank on the other side, probably because the token is requested asynchronously and when the webview is called it didn't come yet.
What can I do?
Either as a url parameter or via postMessage. In both ways you have to wait until the token is available. So load the page or render the webview when the token is available. Or you pass the token via postMessage immediately after the token was received.
The postMessage method is the recommended way, because you can load the page and wait for the token at the same time.
I managed to delay the rendering until the token was ready by using an if on the render method that would not return the webview if a state "loading" is true; then in the function that gets the token I used setState to change the value of loading to false.

Communication Between WebView and WebPage - Titanium Studio

I am working in a Mobile project (using Titanium Studio), in which i have the below situation
1) My Mobile app contacts Rails backend to check some data, say check validity of a
user id.
2) I found a way to load web pages in Mobile app, i.e., WebView
3) I could able to load the desired url, ex http://www.mydomain.com/checkuser?uid=20121
which would return data like status:success
But i need to read this data to show whether the response from server is a success or failure, how do i achieve this?
NOTE : The above mentioned scenario is an usecase, but actually what happens is i load a third party url in WebView and when user enters the data and submits, the result will be posted back to my website url.
EDIT : So the process is like below
1) WebView loaded with third party url like http://www.anyapiprovider.com/processdata
2) User will enter set of data in this web page and submits the page
3) The submitted data will be processed by the apiprovider and it returns data to my web page say http://www.mydomain.com/recievedata
This is the reason why i am not directly using GET using HTTPClient
FYI : I tried to fire Ti.APP events right from the actual web page as suggested by few articles, but most of them says this will work only if the file loaded is in local and not a remote file. Reference Link
Please suggest me if my approach has to be improved.
Thanks
If you don't want to follow Josiah's advice, then take a look at the Titanium docs on how to add a webview.addEventListener('load',... event listener and use webview.evalJS() to inject your own code into the third party HTML.
Maybe you can inject code to trap the submit event and fire a Ti event to trigger the downloading of data from your website.
Communication Between WebViews and Titanium - Remote Web Content Section
I found a solution for my problem
1) Load the http://www.mydomain.com/checkuser?uid=20121 in a webview
2) Let user enter and submit data to third party url
3) Recieve the response from third party url and print only <div id="result">status:success</div> in http://www.mydomain.com/recievedata page.
4) Add event listener for the web view as follows
webView.addEventListener('load', function(data)
{
//Add condition to check if the loaded web page has any div with id = result (to check if this is /recievedata page)
alert(webView.evalJS("document.getElementById('result').innerHTML"));
});
The above alert would print the result status:success, read it in webview load event
and take actions in web accordingly.
It works fine for me.
Instead of loading it in a WebView why not just GET it using a HTTP Client? This is much cleaner, and more standards based:
var xhr_get = Ti.Network.createHTTPClient({
onload : function(e) {
// Here is your "status:success" string
var returnValue = this.responseText;
},
onerror : function(e) {
Ti.API.info(this.responseText);
Ti.API.info('CheckUserProgressOnActivity webservice failed with message : ' + e.error);
}
});
xhr_get.open('GET', 'http://www.mydomain.com/checkuser?uid=20121');
xhr_get.send();

Facebook Built-in Like action callback

Facebook recently introduced the "Built-in Like" as a built-in Open Graph action (see blogpost and documentation). I would like to implement this functionality in my iOS App and be able to listen to the event, when the user completes the like action (similarly to using FB.Event.subscribe in JavaScript). Is this posible and how would you accomplish this?
From the documentation you linked:
To publish a built-in Like action on an Open Graph object, invoke the following HTTP POST request with a user’s access token and the url
of the Open Graph object. This Open Graph object can be of any type.
[example snipped]
which in turn will return the ID of the built-in Like action instance if the call is successful`
The API call itself, which your app makes, will return the ID of the newly created object, there's no special or separate callback - your own code is creating the Like action.