Code Sample: Zobot Script to create a card that displays upcoming webinars from Zoho Meeting

Code Sample: Zobot Script to create a card that displays upcoming webinars from Zoho Meeting

Hi folks,

This took me a few days to figure out, so I am sharing to others.  It is a good example of:
1. how to pull data from another service and then
2. format the data into a card.

I've made comments in the code and fleshed it out with lots of info statements so you can see what is going on each step of the way. 

Once you have the idea, I am sure you'll be able to repurpose and optimise for your own needs. 

This code is inserted into the bot script within a message handler routine.  

// fetch webinar events from Zoho Meeting
info "------------- fetching webinars -----------------";
zsoid = "Zoho_Meeting_ORG_ID";   
        // "Zoho_Meeting_ORG_ID" to be replaced with your organisation id from zoho meetings. You can find this by logging into Zoho Meetings and looking for the long number in the URL of the application.
// you will also need to have an authenticated connection to Zoho Meeting.
 
resp = invokeurl
[
url :"https://meeting.zoho.com/api/v2/" + zsoid + "/webinar.json?listtype=upcoming"
type :GET
connection:"connectionname"
];
       // strip out the actual collection from the returned session item
webinarCollection = resp.get("session");
info webinarCollection;

         responseArray = {};
// holds the arrange of key paired response items
responseArray.add({"text":"Upcoming events...","image":"https://yourcompanyimage.jpg"});
responseArray.add({"text":"IBRS regularly hosts online events to discuss practical, effective approaches to ICT issues."});

// iterate through the list and create the links array for the replies
for each  webinarMap in webinarCollection
{
// extract the webinar details from the map - makes debugging and review easier :-)
eventTopic = webinarMap.get("topic");
info eventTopic;
eventLink = webinarMap.get("registrationLink");
info eventLink;
    eventTime = webinarMap.get("startTimeV1");
    info eventTime;
// add a single entry to the responseArray with this links card details.
responseArray.add( {
    "text":eventTopic,
"type":"links",
"links":{
{"text":"Reserve your spot","url": eventLink ,"target":"_blank"},
{"text":eventTime,"url":eventLink,"target":"_self"}
}
}
);
}
// continue loop until all events added
response.put("action","reply");
response.put("replies",responseArray);
info response;
response.put("input",{"type":"select","options":{"Ask a question from our expert advisors.","Download special reports.","See upcoming events.","Learn about the Cyber & Risk Network.","Request a call.","Recieve weekly research updates."}});
}


Good luck with building your bots.  And please share your code snippets.  Sharing is the way we can all developer much, much faster.