Skip to main content

Communication between In-App and ChuttApp

Obviously, your in-app should have a way to send and receive data to and from ChuttApp. Say, you want to accept payment, you would want to let ChuttApp know about that action, and then take it from there.

See Available Actions to perform.

Before sending and receiving data, ChuttApp will verify your app first. Check the Setup guide for more info.

Sending data to ChuttApp

Using the below snippet, you can send data with the action you want to perform to ChuttApp.

The actions property is required*.

This example shows how to accept transfers from a user, should they want to purchase a product from your store.


// Optional information you would want to pass
const product = {
id: "product-id",
name: "Game Pad"
};

const data = {
action: "SOME_ACTION_HERE",
data: product
};

const requestPayment = () => {
ChuttApp.onSendMessage(data)
};

// with callback
const requestPayment = () => {
ChuttApp.onSendMessage(data, (status, err, data) => {
console.log(status, err, data)
})
};

ChuttApp doesn't do anything with this. Instead, it is emmited back to you, as part of the response data when onReceiveMessage is called.

Data from you

1. action

action expects the type of action to you would want to perfom.

2. eventName

eventName is an optional property. When you want to listen to unique events on the actions you perform, you use this property.

Expected Format

ACTION_NAME / unique_reference

const product = {
id: "product-id",
name: "Game Pad"
};

const data = {
action: "ACCEPT_TRANSFER",
eventName: `ACCEPT_TRANSFER/${product.id}`,
data: product
};

const requestPayment = () => {
ChuttApp.onSendMessage(data, (status, err, data) => {
console.log(status, err, data)
})
};

3. data

data is an optional property. ChuttApp doesn't do anything with the data property. Instead, it is emmited back to you, as part of the response that comes form onReceiveMessage.

Receiving data from ChuttApp

App data from ChuttApp

Before your page is loaded, chuttapp validates and stores the useful data to your App's.

You can access this object by calling:

const appConfig = ChuttApp.appConfig();
console.log(appConfig.darkThemeEnabled)

Data from ChuttApp

{
"isDarkModeEnabled": boolean,
"user": User object,
}
isDarkModeEnabled

isDarkModeEnabled holds a boolean value that tells your if the User has their ChuttApp in the dark-mode theme.

user

user holds a few information about the authenticated User.

These data properties are:

  1. username : string
  2. name : string
  3. country : string

Dynamic data ChuttApp

After an action is complete, you would want to handle whatever response that comes back from ChuttApp.

This case, we have a function you can listen from.


ChuttApp.onReceiveMessage(eventName, (status, err, data) => {
console.log(status, err, data)
})