Click here to Skip to main content
15,610,998 members
Articles / Web Development / HTML
Posted 7 Jul 2008


24 bookmarked

IVR used in Google Calendar Event

Rate me:
Please Sign up or sign in to vote.
3.20/5 (5 votes)
20 Aug 2008CPOL5 min read
When the event in Google Calendar raises up,call user in IVR

Introduction for the IVR and Google Calendar

Many people have the experience of using the Calendar,it does facilitate our works and lifes.But most of the Calendars are based on text alert, that means you can only get the reminder event in front of your computer.

So I think if the Calendar can remind me by phone.If I want to achieve this idea, I need a Calendar that can provide me APIs, a technology that can make me to call through programming.

Fortunately,these technologies for this idea have been provided ,Google Calendar and IVR(Interactive Voice Response, based on phone call).

I've posted some articles to introduce IVR.You can view them here:

IVR used in Voicent Gateway
IVR used in Facebook

Or, you can investigate it throught the Google Search,there are lots of article to introduce it.Now, we'll mainly concentrate on the Google Calendar.

Google Calendar allows client applications to view and update calendar events in the form of Google data API ("GData") feeds. Your client application can use the Google Calendar data API to create new events, edit or delete existing events, and query for events that match particular criteria.

There are many possible uses for the Calendar data API. For example, you can create a web front end for your group's calendar that uses Google Calendar as a back end. Or you can generate a public calendar for Google Calendar to display, based on your organization's event database. Or you can search relevant calendars to display a list of upcoming events on those calendars.

You can view these articles to comprehend the Google Calendar:

What are the Google Data APIs?

Google Data APIs Client Libraries

Google Data APIs Samples

Developer's Guide

These articles provide detailed introductions and examples for using the .NET Client Library to work with the Google Calendar service. For help setting up the client library, see the Getting Started Guide. You will find examples of adding events, updating events, deleting events and querying events. If you're interested in understanding more about the underlying protocol used by the .NET Client Library to interact with the Calendar data API, please see the protocol tab.

After you read those,you can continue the following topics.

How to create Calendar Service

The CalendarService class represents a client connection (with authentication) to a Calendar service. To request a feed using the .NET client library, first instantiate a new CalendarService object and authenticate the user. Then use the Query method to retrieve a CalendarFeed object that contains entries for all of the user's calendars.

You can authenticate the user by WebForm or WinForm,the WebForm is called
AuthSub proxy authentication, and the WinForm is called ClientLogin username/password authentication.

In order to authenticate the applications using the AuthSub login protocol,you must get the Session token.

First,construct a AuthSubRequest URL for your application, make a .NET client library call as follows:

The getRequestUrl method takes several parameters :

  • "next" URL ,which is the URL that Google will redirect to after the user logs into their account and grants access;
  • scope ,as determined in the previous section;
  • two Booleans, one to indicate whether the token will be used in registered mode or not, and one to indicate whether the token will later be exchanged for a session token or not.

The above example shows a call in unregistered mode (the first Boolean is false), for a token that will be exchanged for a session token later (the second Boolean is true); adjust the Booleans appropriately for your application.

After the user follows the link to the AuthSub page at Google and logs in, the AuthSub system then redirects the user back to your application, using the "next" URL you provided.

When Google redirects back to your application, the token is appended to the "next" URL as a query parameter. So in the case of the above "next" URL, after the user logs in, Google redirects to a URL like Therefore, the token is accessible as a variable in the ASP page's Request.QueryString object.

The token you initially retrieve is always a one-time use token. You can exchange this token for a session token using the AuthSubSessionToken URL, as described in the AuthSub documentation. Your application can make this exchange using the .NET client library as follows:

Session["sessionToken"] = 
                AuthSubUtil.exchangeForSessionToken(Request.QueryString["token"], null); 

Now you are ready to use the session token to authenticate requests to the Calendar server by placing the token in the Authorization header.

GAuthSubRequestFactory authFactory = 
                new GAuthSubRequestFactory("cl", "CalendarSampleApp");
authFactory.Token = Session["sessionToken"].ToString();
Service service = new Service("cl", authFactory.ApplicationName);
service.RequestFactory = authFactory; 

To use ClientLogin, invoke the setUserCredentials method of CalendarService, specifying the ID and password of the user on whose behalf your client is sending the query. For example:

CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("", "mypassword");

You can get a list of a user's calendars by sending an authenticated GET request to the allcalendars feed URL: 

You also can query to retrieve a list of calendars that the authentiated user has access to: 

After instantiate a new CalendarService object and authenticate the user, then use the Query method to retrieve a CalendarFeed object that contains entries for all of the user's calendars.

// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
/*The parameter applicationName in the constructor of CalendarService is random,
you can enter any name you want.*/
myService.setUserCredentials("", "mypassword");

CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("");
CalendarFeed resultFeed = service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach (CalendarEntry entry in resultFeed.Entries)
    Console.WriteLine(entry.Title.Text + "\n");

The CalendarService the key to get the services of Google Calendar,when you finish this,you can get what you want.In the next topic,I will follow that way to get the StartTime of a Calendar Event,and call user using the IVR.

Call user when the event rises up

My idea is first I do a callback to the server side from the client using JavaScript. In the server side, using CalendarService query to retrive the StartTime of the EventEntry from the Calendar Service. Then return the time string to the client, in the client, using the JavaScript method setTimeout to circularly check the returned time with the client time. When they are equal,go back to the server side,construct a IVR object to call user.

This is the html code:

 <head id="Head1" runat="server">
    <script language="javascript" type="text/javascript">
    var stopTimmer;//Timeout ID
    var strReturn;//The value returned from the server
    function ReceiveDateFromServer(valueReturnFromServer)
        document.getElementById("ServerTime").innerHTML = "DateTime of Server:"
        + valueReturnFromServer;
        strReturn = valueReturnFromServer;
        //Start the reminder to remind the user about the Calendar Event.
    function GetServerTime(format)
        CallBackToServer(format, "");//Send callback to server.
    function TriggerEvent()
        //Get the current date with US culture.
        var localDate = Date.parse((new Date()).toString("en-US"));
        document.getElementById('NowTime').innerHTML = "DateTime of Now:" 
                 + (new Date()).toString("en-US");
        var serverDate = Date.parse(strReturn);
        var diff = localDate - serverDate;
        //Compare the date returned from server with the client date.
        if (diff >= 0)
            /*If the client is on time,
            then clear the Timeout and start the server event to call user.*/
            var btnCall = document.getElementById('btnCall');
            if (btnCall != null)
      ;//Call the server event to make a call.
            return false;
        /*Recurrence,check every 1 second,
         until the current time equals the time returned from Calendar.*/
        stopTimmer = setTimeout("TriggerEvent()", 1000);
    <form id="form1" runat="server">
        <asp:Button ID="btnStartReminder" runat="server" Text="Start Reminder" 
        OnClientClick="javascript:GetServerTime('');return false;" />
        <br />
        <br />
        <span id="ServerTime">
            DateTime of Now<%= DateTime.Now.ToString("yyyy-MM-dd HHHH:mm:ss") %>
        <br />
        <span id="NowTime"></span>
        <div style="display:none">
            <asp:Button ID="btnCall" runat="server" onclick="CallUser" Text="Button" />

This is the codebehind:

You'll need the following using statements:

using System.Globalization;
using Google.GData.AccessControl;
using Google.GData.Calendar;
using Google.GData.Client;
using Google.GData.Extensions; 

In order to do callback,your class must inherit from the ICallbackEventHandler interface.

public partial class CalendarEvent : System.Web.UI.Page, ICallbackEventHandler
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                string strRefrence = Page.ClientScript.GetCallbackEventReference(

                string strCallBack = "function CallBackToServer(callArgs, callContext) {"
                    + strRefrence + "};";


        private string eventMessage = String.Empty;

        public string GetCallbackResult()
            DateTimeFormatInfo myDTFormatInfo = 
                new CultureInfo("en-US", false).DateTimeFormat;
            DateTime eventStartTime = DateTime.Now;
            //Create a CalenderService and authenticate
            CalendarService calService = 
                new CalendarService("GoogleCalendarAndIVRSampleApp");
            calService.setUserCredentials("", "password");

            string feedUri = 
            //Get the Calendar Event you wanted.
            Google.GData.Calendar.EventQuery eventQuery = 
                new Google.GData.Calendar.EventQuery(feedUri);
            //This is the title of your wanted event.
            eventQuery.Query = "NewEvent of mine";
            EventFeed resultEventFeed = calService.Query(eventQuery);

            Google.GData.Calendar.EventEntry myEventEntry = 
            //If you want to remind the user when the event starts,you can do like this:
            eventStartTime = myEventEntry.Times[0].StartTime;

            //And get the summary of the event.
            eventMessage = myEventEntry.Summary.Text;
            //Of cource,you can get the where,etc.

            return eventStartTime.ToString("F", myDTFormatInfo);

        public void RaiseCallbackEvent(string eventArgument)
            //You can write some useful code here.

        protected void CallUser(object sender, EventArgs e)
            //Call user
            VoicentIVR callUserByIVR = new VoicentIVR("localhost", 1982);
            callUserByIVR.CallText("User's phone", eventMessage, true);

The class VoicentIVR is contained in the solution in the ZIP file for downloaded.

Btw,my environment is VS2008,but I don't use the features of .NET Framework 3.5, so I guess these codes can also work fine in VS2005.

Points of Interest

IVR,Google Calendar,Skype


IVR introduce

IVR Starter


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionAll-Day's Calendar Pin
zhongzhang7-May-13 23:12
zhongzhang7-May-13 23:12 
AnswerRe: All-Day's Calendar Pin
zhongzhang7-May-13 23:45
zhongzhang7-May-13 23:45 
GeneralHow to make IVR work Pin
MithunChopda28-Jun-12 14:18
MithunChopda28-Jun-12 14:18 
GeneralSource Problem Pin
Armando Airo'3-Aug-08 23:00
Armando Airo'3-Aug-08 23:00 
GeneralRe: Source Problem Pin
jedliu20464-Aug-08 14:51
jedliu20464-Aug-08 14:51 
What files,can you give me your exceptions?

GeneralRe: Source Problem Pin
Armando Airo'5-Aug-08 1:53
Armando Airo'5-Aug-08 1:53 
GeneralRe: Source Problem Pin
jedliu20465-Aug-08 15:19
jedliu20465-Aug-08 15:19 
RantFix formating Pin
Pete Souza IV8-Jul-08 4:38
professionalPete Souza IV8-Jul-08 4:38 
GeneralRe: Fix formating Pin
jedliu20468-Jul-08 16:27
jedliu20468-Jul-08 16:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.