Here is where I found the solution:
https://support.ptc.com/help/thingworx/platform/r9.5/en/#page/ThingWorx/Help/Composer/Things/ThingSubscriptions/ThingSubscriptions.htmlhttps://support.ptc.com/help/thingworx/platform/r9.5/en/#page/ThingWorx/Help/Composer/Things/ThingSubscriptions/ThingSubscriptions.html
var message = "New Event with type: " + eventName + ". " + ThingName + "'s " + propName + " changed from " + oldValue + " at " + oldValueTime + " to " + newValue + " at " + newValueTime + ".";
handlerIDs = NotificationDefinitions["Sample_RoA"].GetAvailableHandlers();
//handlerID = handlerIDs.rows[3].handlerID;
var handlerIDsList = handlerIDs.rows;
var telegramHandlerID = "";
for(var i = 0; i < handlerIDsList.length; i++) {
// Check if contentName contains 'Telegram'
if(handlerIDsList[i].contentName.indexOf("Telegram") !== -1) {
telegramHandlerID = handlerIDsList[i].handlerID;
break; // Exit the loop once the ID is found
}
}
//logger.warn("handlerID: " + telegramHandlerID);
//logger.info("handlerID: " + telegramHandlerID);
var UserRecipients = NotificationDefinitions["Sample_RoA"].GetUserRecipientsOfEvent({
handler: telegramHandlerID /* STRING */,
propertyName: propName /* STRING */,
alertName: "" /* STRING */,
entityType: "Thing" /* STRING */,
entityName: ThingName /* STRING */,
eventName: eventName /* STRING */
});
//logger.warn("Recipient List: " + UserRecipients.rows);
var UserRecipientsList = UserRecipients.rows;
for (var j = 0; j < UserRecipientsList.length; j++){
var User = UserRecipientsList[j].name;
let params = {
headers: {
token: token/*token from the configuration*/
},
url: 'https://api.telegram.org/bot'+token+'/sendMessage',
content: {
chat_id: Users[User].TelegramID, //this is the telegram user ID= '-xxx’
text: message
}
};
// logger.warn("message: " + message);
let post = Resources["ContentLoaderFunctions"].PostJSON(params);
}