getNotification: Get the notification

Function Description:

Get the notification bar message for the device.
Note:
First, you need to set up Total Control's mobile client, activate the messaging service, and Total Control's computer client and script can get the content of each notification bar message.
Steps for the Total Control mobile client to activate the messaging service:
1. Open the mobile terminal Total Control software
2. Click the [Setting] button in the upper right corner.
3. Click the [Setting message service] button in the [Message Setting] column and check the radio button next to [TC notification listener service].

Corresponding JS API:
Notification(device, app, match)
getNotification()
Version:

For Total Control version 6.9.0 and higher

Whether to support multiple devices:

No

Resource Information:

Method GET
URL .../notifications?position=:num&count=:count&device=:device&app=:app&match=:match
Requires authentication? Yes


Method Parameters:

Parameter Type Required Description
position Int Yes Get the start position of the notification message (required), the minimum value is 1.
count String No Get the number of notification bar messages. If you do not fill in this value, it means to get the message of the specified position [position].  
device String No Gets the specified device message. The value is a string or an array of strings (not required), for example: ["device@1174886816","device@1174886817"], the default is sigmaConst.Any.
app String No Gets the specified package name message. The value is a string or an array of strings (not required), for example: ["com.sigma_rt.totalcontrol","com.tencent.qqmusic"], the default is sigmaConst.Any.
match String No Gets the specified text message, a string or an array of strings (not required), for example: ["Music", "Power"], defaults to sigmaConst.Any.


Response Parameters:

A JSON string representing an array of objects with the following fields:

Field Type Description
status Boolean Return true for success and null for failure
value String/Object String. If the value of status is a null object, an error message or empty string is returned.
Object. If the value of status is true,it returns the obtained notification bar message object.
It contains the following fields:
"app": Software name
"text": The content of the notification bar message obtained.
"time": The time the device received the message.
"id": Device id


Request Example:
http://localhost:8090/TotalControl/v1/notifications?token=t1QKNwJ3ok53vKLx&position=1&count=40&device=device@1174886816&app=["com.sigma_rt.totalcontrol","com.tencent.qqmusic"]&match=test
Response Example:

If this API executes successfully, it returns:

{
	"status": true,
	"value": [{
		"app": "com.sigma_rt.totalcontrol",
		"text": "Click to enter the program",
		"time": 1539833828000,
		"id": "device@1174886816"
	}]
}

If the value of HTTP status code is 200, but the value of status is a null object, it returns:

{
    "status": null,
    "value": "<Error message>"
}


Example:

Warm tip:
Get the token needed for Total Control script development,see here.
Get the id value of the master device, see here.

RingoJS Example:
// Import the packages
var {request} = require("ringo/httpclient");
var base64 = require("ringo/base64");

// The username and password are separated by a single : and sent on the wire base64 encoded
var userpass = base64.encode("sigma:3D391497");

// First step: Get the API token
var gettoken = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/login",
	headers: {
		"Authorization": userpass
	}
});
var ret_token = JSON.parse(gettoken.content); 
var token = ret_token.value.token; 
print("//The value of token is:" + token);

// Second step: Get the device id value of the master device
var getdevice = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/devices/main?token=" + token
});
var device = JSON.parse(getdevice.content).id; 
print("//The value of device ID is:"+ device);

// Third step: Execute this REST API
var resp = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/notifications",
	data: {
		"position":1,
		"count":3,
		"device":device,
		"app": ["com.sigma_rt.totalcontrol","com.tencent.qqmusic"],
		"token": token,
	}
});
var obj = JSON.parse(resp.content); 
ret =obj.status;
if (ret == true) {
	print("//Executed successfully,Return value: \n"+resp.content);	
} else if (ret != true & resp.status == 200){
	print("An error message is returned: "+resp.content);
} else {
	print("This API failed to execute.");
}
The running result of the RingoJS:

If it executes successfully, it will return:

//The value of token is:QG097nhLzTSn9OZ8
//The value of device ID is:device@230441652
//Executed successfully,Return value: 
{"status":true,"value":[{"app":"com.sigma_rt.totalcontrol","text":"Click enter application","time":1555320952000,"id":"device@230441652"},{"app":"com.tencent.qqmusic","text":"Touch for more information or to stop the app.","time":1555320968000,"id":"device@230441652"},{"app":"com.sigma_rt.totalcontrol","text":"Screenshot captured. Tap here to view.","time":1555321014000,"id":"device@230441652"}]}
Python Example:
#!/user/bin/python
#-*- coding:utf-8 -*-
import base64
import requests

# The username and password are separated by a single : and sent on the wire base64 encoded
user_pass = 'sigma:3D391497'
encodeStr = base64.b64encode(user_pass.encode("UTF-8"))

# First step: Get the API token
LoginUrl = "http://localhost:8090/TotalControl/v1/login"
response = requests.get(LoginUrl, headers={'Authorization':encodeStr})
print("Get the token,Return value: ",response.json())
token = response.json()['value']['token']
print("The value of token is: ",token)

# Second step: Get the device id value of the master device
if token is not None:
    GetDeviceUrl = "http://localhost:8090/TotalControl/v1/devices/main?token=" + token
    response = requests.get(url=GetDeviceUrl)
    print("Get the device id,Return value: ", response.json())
    device = response.json()['id']
    print("The value of device id is: ", device)
    if device is not None:
        # Third step: Execute this REST API
        APIUrl = "http://localhost:8090/TotalControl/v1/notifications"
        data = {
            "position": 1,
            "count": 2,
            "device": device,
            "app": "com.sigma_rt.totalcontrol",
            "match": "Screenshot",
            "token": token
        }
        response = requests.get(url=APIUrl, params=data)
        ret = response.json()['status']
        # Determine if this REST API is executed successfully
        if ret is True:
            print("Executed successfully,Return value: ", response.json())
        elif response.status_code == 200 and ret is not True:
            print("An error message is returned: ",response.json())
        else:
            print("This API failed to execute.")
    else:
        print("Failed to get device id.")
else:
    print("Failed to get token.")
The running result of the python:

If it executes successfully, it will return:

Get the token,Return value:  {'status': True, 'value': {'token': 'QG097nhLzTSn9OZ8'}}
The value of token is:  QG097nhLzTSn9OZ8
Get the device id,Return value:  {'id': 'device@230441652'}
The value of device id is:  device@230441652
Executed successfully,Return value:  {'status': True, 'value': [{'app': 'com.sigma_rt.totalcontrol', 'text': 'Screenshot captured. Tap here to view.', 'time': 1555321014000, 'id': 'device@230441652'}, {'app': 'com.sigma_rt.totalcontrol', 'text': 'Screenshot captured. Tap here to view.', 'time': 1555323300000, 'id': 'device@230441652'}]}