Click here to Skip to main content
12,820,521 members (29,586 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 7 Jul 2008

IVR used in Google Calendar Event

, 20 Aug 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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 thesetUserCredentials 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">

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)


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionAll-Day's Calendar Pin
zhongzhang8-May-13 0:12
memberzhongzhang8-May-13 0:12 
AnswerRe: All-Day's Calendar Pin
zhongzhang8-May-13 0:45
memberzhongzhang8-May-13 0:45 
GeneralHow to make IVR work Pin
MithunChopda28-Jun-12 15:18
memberMithunChopda28-Jun-12 15:18 
RantFix formating Pin
psouza4micronet8-Jul-08 5:38
memberpsouza4micronet8-Jul-08 5:38 
GeneralRe: Fix formating Pin
jedliu20468-Jul-08 17:27
memberjedliu20468-Jul-08 17: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 21 Aug 2008
Article Copyright 2008 by jedliu2046
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid