Monitoring Notifications With Regular Expressions

Monitoring Notifications With Regular Expressions

Subscribe to our newsletter and never miss any upcoming articles

Listen to this article

Introduction:

The monitor verb in the @protocol is used to stream the received notifications.

Please check the MonitorVerbHandler source code to learn more about the implementation of the monitor verb.

The article focuses on the usage of the monitor verb and how to filter notifications using regular expression(regex).

Description:

The monitor verb is used to stream the notification received from the other atsign user. Optionally a regular expression can suffix the monitor verb to filter the notifications. When regex is provided, only the notifications that match the regex are returned.

Example:

@alice notifying @bob

Var currentAtSign = '@alice';

var atKey = AtKey()
 ..key = 'phone'
 ..sharedWith = '@bob’
 ..sharedBy = currentAtSign;

var value = '+1 100 200 345';

var result = await atClient.notify(atKey, value, OperationEnum.update, notifier: 'system');

Monitor Verb running on @bob

await AtClientImpl.createClient(
   '@bob', '@persona', preference);
var atClient = await AtClientImpl.getClient('@bob’);
await atClient.startMonitor(preference.privateKey, _notificationCallBack);

Response

notification: {"id":"c6fab088-9e01-4374-a1da-182589eb8c7f","from":"@alice","to":"@bob","key":"@bob:phone@alice","value":null,"operation":"update","epochMillis":1613889831624}

notification: {"id":"c6fab088-9e01-4374-a1da-182589eb8c7f","from":"@alice","to":"@bob","key":"@bob:address@alice","value":null,"operation":"update","epochMillis":1613889831876}

Monitor Verb running on @bob with regex.

await AtClientImpl.createClient(
   '@bob', '@persona', preference);
var atClient = await AtClientImpl.getClient('@bob’);
await atClient.startMonitor(privateKey, acceptStream,regex: 'phone'
);

Response

notification: {"id":"c6fab088-9e01-4374-a1da-182589eb8c7f","from":"@alice","to":"@bob","key":"@bob:phone@alice","value":null,"operation":"update","epochMillis":1613889831624}

We are working to make the Internet better. Please come code with us!

 
Share this
Proudly part of