With Stringee, Client Apps can monitor status of each other in real-time, like:
If client A wants to monitor the change of an attribute of Client B, both sides have to define a topic, i.g. topic_1
To allow an App to Publish or to Subcribe to a Topic, you can add "subscribe" values and "attributes" array into the Access Token Payload; read more about Access Token here.
To be specific, you add at least 1 of 2 fields below in to the Payload:
[{
"attribute": "ATTRIBUTE_NAME",
"topic" "TOPIC_NAME"
}]
There are 2 default attributes (you can't define new attributes with same name):
Besides those 2 attributes, you can define new ones freely for the Clients.
There is 1 default Topic:
An example of Access Token Payload:
{
"jti": "...-1554197947",
"iss": "...",
"exp": 1555197947,
"userId": "agent_1",
"subscribe": "online_status_GRDHG0HI,ALL_CALL_STATUS,agent_manual_status",
"attributes": [{
"attribute": "onlineStatus",
"topic": "online_status_GRDHG0HI"
},
{
"attribute": "call",
"topic": "call_GRDHG0HI"
},
{
"attribute": "manual_status",
"topic": "agent_manual_status"
}
]
}
After being authorized with above Access Token, the App will:
Subscribe to Topics:
Publish:
GET https://api.stringee.com/v1/users/USER_ID
Response:
{
"loginTime": 1554204151774,
"attributes": [
{
"attribute": "onlineStatus",
"value": "online"
},
{
"attribute": "call"
},
{
"attribute": "app_is_foreground",
"value": true
}
],
"chatCustomer": false,
"userId": "USER_ID"
}
Notice: REST API must be authorized, more details at: https://developer.stringee.com/docs/call-rest-api/call-rest-api-authentication
a) By REST API
PUT https://api.stringee.com/v1/users/USER_ID/attributes
[
{
"attribute": "ATTRIBUTE_NAME",
"value": "NEW_VALUE"
}
]
Response:
{
"loginTime": 1554204151774,
"attributes": [
{
"attribute": "onlineStatus",
"value": "online"
},
{
"attribute": "call"
},
{
"attribute": "ATTRIBUTE_NAME",
"value": "NEW_VALUE"
}
],
"chatCustomer": false,
"userId": "USER_ID"
}
Notice: REST API must be authorized, more details at: https://developer.stringee.com/docs/call-rest-api/call-rest-api-authentication
b) From Client App
Web:
stringeeClient.changeAttribute('ATTRIBUTE_NAME', "NEW_VALUE")
iOS:
[stringeeClient changeAttribute:@"ATTRIBUTE_NAME" value:@"NEW_VALUE" completionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"changeAttribute -- %@", message);
}];
Web:
stringeeClient.on('messagefromtopic', function (data) {
console.log('++++++++++++++ messagefromtopic++++', data);
});
Format of returned data (response):
{
"topic": "online_status_GRDHG0HI",
"message": {
"newValue": "online",
"callEnded": true,
"attribute": "onlineStatus",
"userId": "user_1",
"projectId": 25,
"timestamp": 1554261314286
}
}
iOS: Implements the StringeeConnectionDelegate protocol
- (void)didReceiveMessageFromTopic:(StringeeClient *)stringeeClient message:(NSDictionary *)message fromUserId:(NSString *)userId {
NSLog(@"didReceiveMessageFromTopic %@ - %@", message, userId);
}