com.innovaphone.calendar

The com.innovaphone.calendar services api enables apps to use the whole websocket communication API from calendar. The users App uses this functionality on the C++ part of the app for reading, creating and modifying appointments as well as special requests that can be used for syncing.
All messages are send as JSON strings and must use the mt property which is the message type.

GetService

See services for the information how to exactly work with IServices!
When accessing the calendar using the service api (which means, that the user to access will be authenticated by the PBX), the acces to the calendar is on admin level. That means, that full access to the calendar database for all users is granted. Appointments for all users can be read (ignoring the private flag), updated and created. This comes in handy for synchronizing purposes.

IServicesApi * services = ...;    // must be retrieved within the PBX websocket connection PbxInfo message to the app service.
IService * service = services->GetService("com.innovaphone.calendar");
class IAppWebsocketClient * awsClient = IAppWebsocketClient::Create(iomux, this, tcpSocketProvider, tlsSocketProvider, dns, log);
awsClient->Connect(service->GetWebsocketUrl(), service->GetName(), session->services->CreateAuthenticator());

AppLogin

If you do not work with IServices and you know the intance password of the calendar instance, you can also use the standard AppLogin mechanism to login to calendar.
Note that using AppLogin doesn't give the ability to access the data of all users for synchronizing purposes. For this, admin rights are needed, which only will be granted for connections comming over a service, authenticated by the PBX.

Messages send to the service

Header
GetAppointments
GetAppointment
WriteAppointment
DeleteAppointment
GetUser

Messages received by the service

AppointmentInfo
GetAppointmentsResult
GetAppointmentResult
WriteAppointmentResult
DeleteAppointmentResult
UserInfo
GetUserResult

Additional infos

Appointment properties

Calendar JSON messages

Below is a detailed description of each message. The messages have all the same header. Note that all messages MUST include the header properties.

Header

{
    "mt": MessageID,
    "src": "string"
}

This header must be set for all messages. The properties that will be added below depending on the message sent. Details about that fields can be found in the description of each message below.

Properties

string msgThe name of the message. Must be given.
string src(Optional) A string that will be echoed in the result message. This field is optional.

GetAppointments

{
    "mt": "GetAppointments",
    "src": "uniqueIDString",
    "userID": number,
    "start": number,
    "end": number,
    "syncID": number,
    "syncDatabase": string,
    "close": bool
    "properties": [appointmentProperties]
}

This message returns all appointments for the given time range and also registeres the app receiving continous updates. The src property is obligatory for that message. Each response will echo the value of src. With this, an app can define different sets of parameters to get appointments for (as well as further updates).

The message leads to a couple of responses. Aft first, a GetAppointmentsResult message will be received as answer. The status of the message tells, what is going to happen. If the status is "ok", then the calendar will send all available appointments for the given time range via AppointmentInfo messages. The last message will also have the property last set to true, to signal that all available data had been send. After that, the calendar will observe the database for changed and send each change for the requested user and time range with another AppointmentInfo message. Each appointment will be send with an own AppointmentInfo message.

The parameters for an existing observation can be changed by sending GetAppointments with the same src value again. That will lead to the same process as sending the message the first time. Note that each AppointmentInfo sended before the GetAppointmentResult response can be ignored, because they are part of the previous and now outdated GetAppointments message.

To stop from getting further updates, GetAppointments must be send again with the property close set to true. This will lead to an GetAppointmentsResult message, too, showing that the observation for changes is stopped. To continue receiving updates, GetAppointments must be send. When the connection closes, each observation will be canceled automatically.

The message can also be used to synchronize with the calendar database. For this, the property syncID and syncDatabase must be set. To do a first-time sync, set syncDatabase to an empty string and syncID to 0. To sync all data changed from the time of the last sync, set syncID and syncDatabase to the lastest values received. The syncID is a property of an appointment and must be requested via the properties array, while the syncDatabase will be received through the GetAppointments message (only if syncID and syncDatabase are given to GetAppointments). Note that for synchronizing purposes it will be a good idea to request all appointment properties. If there is need to syhcnronize multiple users, each user should be synchronized seperately. So at first send a GetAppointments message for the first user, until AppointmentInfo with last set to true will arraive (or GetAppointmentsResult with status set to noData). After that, only the incomming updates must be handled.

When requesting appointments from other users, the title will set to "Private" if the private flag of an appointment is set to true. Except for connections established by a service (authenticated through the PBX). In that case, the title will be as saved in the database. This is important for synchronizing purposes. Be careful and respect the users privacy! If there is need to synchronize the appointments of all users, one user after an other should be synchronized to spare resources.

Properties

string srcThe required unique string that will be used as id for all resulting AppointmentInfo and GetAppointmentsDone messages. The string must be unique per connection only and can be freely choosen.
ulong64 userID(Optional) The id for the user to get the appointments for. If not given, the user authenticated for the appWebsocket connection will be used.
ulong64 start(Default 0) The start of the time range.
ulong64 end(Default max of ulong64) The end of the time range.
ulong64 syncID(Optional) The id of the last sync. Set to 0 to initiate a first-time sync. If syncID is given, the property syncDatabase must be given, too.
string syncDatabase(Optional) The id for the database synced with. Set to an empty string to initiate a first-time sync. If syncDatabase is given, the property syncID must be given, too.
bool close(Optional, default false) If the property exists and is set to true, the stream will be closed. To close a stream, the src and close property are enough, other properties (if sent) will be ignored.
array propertiesThe array holding the requested properties the calendar should send for each appointments. If not given, all for an appointment relevant properties will be sent. See Appointment properties for a detailed description.

Remarks

If the syncID property is given, the synchronizing mode will be enabled. That leads to the following differences:

GetAppointmentsResult

{
    "mt": "GetAppointmentsResult",
    "src": "streamIDString",
    "syncDatabase": string,
    "status": "statusCodeString",
    "errorMsg": "errorMessageString"
}

This is the response for GetAppointments.

Properties

string srcThe id given to GetAppointments.
string syncDatabaseThe id of the database - used for syncing.
string statusThe status code.
string errorMsgThe error message (only exists, if status is error).

Remarks

The values for status are:

AppointmentInfo

{
    "mt": "AppointmentInfo",
    "src": "uniqueIDString",
    "last": bool,
    "status": "statusCodeString",
    "properties": {
        appointmentProperties
    }
}

This message will be send to an open appointment stream.

Properties

string srcThe id given to GetAppointments.
status statusThe status code for the appointment.
bool lastThis property will be send (and set to true) if the message will hold the last appointment read from the database. Each AppointmentInfo send from now on are send because of updates to the calendar database.
object appointmentAn object with the requested properties for the appointment.

Remarks

When sending GetAppointments, the calendar will send all appointents for the requested time range available first. These messages won't have a status property. AppointmentInfos send later because of changes to the calendar database (in the defined time range), will be send with the status property to tell the reason for the update. In that case, status have one of the following values:

GetAppointment

{
    "src": optionalString,
    "mt": "GetAppointment",
    "id": number
}

Returns the appointment with the requested id. The message will lead to a GetAppointmentDone response message with the requested appointment.

Properties

ulong64 idThe id of the requested appointment.

GetAppointmentResult

{
    "mt": "GetAppointmentResult",
    "src": optionalString,
    "status": "statusString",
    "errorMsg": "errorMessageString",
    "properties": [appointmentProperties]
}

The answer for GetAppointment with the requested appointment.

Properties

string statusThe status of the request.
string errorMsgThe error message, if status is error.
object propertiesAn object with the requested properties of the appointment. See Appointment properties for a detailed description

Remarks

Status will be one of the following values:

WriteAppointment

{
    "mt": "WriteAppointment",
    "src": optionalString,
    "properties": [appointmentProperties]
}

Write the appointment with the given properties to the database. This message will lead to a WriteAppointmentResult response message. The message will be used to create or change an appointment. The details of an appoimtment are defined by the appointment properties inside the properties object. In general, all properties must be set, with some exceptions:

Properties

object propertiesThe properties for the appointment Must be all properties necessary for the type of appointment to write. See Appointment properties for a detailed description.

WriteAppointmentResult

{
    "mt": "WriteAppointmentResult",
    "src": optionalString,
    "id": number,
    "status": "status",
    "errMsg": "errorMessageString"
}

Will be sent as a result of WriteAppointment.

Parameters

ulong64 idThe id of the appoitment written.
string statusThe status of the process.
string errMsgThe error message if status is error.

Remarks

Status will be one of the following values:

DeleteAppointment

{
    "mt": "DeleteAppointment",
    "src": optionalString,
    "id": number
}

Will delete the appointment with the given id. This message will lead to a DeleteAppointmentResult response message.

Parameters

ulong64 idThe id of the appointment to delete.

DeleteAppointmentResult

{
    "mt": "DeleteAppointmentResult",
    "src": optionalString,
    "status": "status",
    "errMsg": "errorMessageString"
}

Will be sent as a result of DeleteAppointment.

Parameters

string statusThe status of the process.
string errMsgThe error message if status is error.

Remarks

Status will be one of the following values:

GetUser

{
    "mt": "GetUser",
    "src": optionalString,
    "close": bool
}

Get all available users and observes the user database of the calendar for changes. Instead of GetAppointments only on observation per connection will be allowed.

The message will lead to couple of responses. At first, a GetUserResult message will be send. If the status of that message is not error, a bunch of UserInfo messages will follow. The last user for the request will be send the the last flag of the UserInfo message set. After that, update for a user or the user list will be send with additional UserInfo messages. The updates will be send until the connection had been closed or GetUsers will be send again with the close flag set to true.

Parameters

bool close(Optional, default false) If the property exist and is set to true, the observation will be canceled.

UserInfo

{
    "mt": "UserInfo",
    "src": optionalString,
    "status": "statusString",
    "last" : boolean
    "userID": number,
    "userName": string
}

Will be send for each user after sending GetUser as well as every time, if something changes in the user database.

Parameters

string statusThe status of the user.
bool lastThis property will be send (and set to true) if the message will hold the last user read from the database. Each AppointmentInfo send from now on are send because of updates to the calendar users database.
ulong64 userIDThe id of the user.
string nameThe user name.

Remarks

Status only will be send for update messages and will be one of the following values:

GetUserResult

{
    "mt": "GetUserResult",
    "src": optionalString,
    "status": "statusString",
    "errorMsg": "errorMessageString"
}

Will be send after sending a GetUser message, If the status will be ok (GetUser sent the first time) or restarted (GetUser sent again to get a while refresh), a bunch uf UserInfo messages will folow, whith the last UserInfo message having the last flag set to true. That message also occures after the observation had been closed because of a GetUser message with close set to true.

Parameters

string statusThe status of the GetUser process.
string errMsgThe error message, if status is error.

Remarks

Status will be one of the following values:

Appointment properties

{
    appointmentProperties
}

Each message that writes, requests or sends appointments need a list of properties of the appointment. The requested properties will be send in the respose and can be one of the properties below. For creating or updating appointments, all relevant properties must be set. For requesting appointments, the properties id, userID and type will always be send. Note that the properties array will be optional for messages that request appointments (GetAppointments, GetAppointment). In that case, all relevant properties for an appointment will be send. Only properties that exist for an appointment will be part of the answer. Readonly properties (type, syncID, changedAt) will be ignored if tried to use for WriteAppointment.

Note: The recurring masters have additional fields to calculate the series. The calculation will be done by the calendar using functions provided by the innovaphone SDK. The properties for the recurring masters depending highly on that functions, so it is recommended to read the time occurrence documentation to understand the usage of the properties as well as the values of the fields (like for the days property, which is a bitfield).


PropertyDatatypeDescription
idlong64(Will always be send) The id of the appointment in the calendars database. A negative value indicates a calulated occurrence of a recurrign master.
userIDlong64(Will always be send) The id of the user the appointment belongs to.
typestring(Will always be send) The type of the appointment. Will be NORMAL, RECURRING_MASTER, DELETED_EXCEPTION, MODIFIED_EXCEPTION or OCCURRENCE. Note that OCCURRENCE canot be used for WriteAppointment.
syncIDlong64(Readonly) The sync id of appointment.
titlestringThe title of the appointment. Will be "Private", if the appointment is private and requested by another user which is not a service.
startDatelong64(UTC) The start of the appointment. For recurring masters, this will be the start of the series.
endDatelong64(UTC) The end of the appointment. For recurring masters, this will be the end of the series (while 0 means, that the series will never end).
locationstringThe location for that appointment. If missing, no location is set.
allDayboolFlag whether the item is an whole-day appointment or not.
privateboolFlag whether the item is private not.
activitystringThe activity. Will be free, busy, away or tentative.
changedAtlong64(Readonly) The timestamp of the last changes made.
organizerstringThe organizer who created the appointment. If not given, no organizer is set.
notesstringThe notes of the appointment.
Additional properties for occurrences (calculated from recurring masters):
recurringMasterIDlong64(Readonly) The id of the recurring master, the occurrence had been created from.
Additional properties for recurring exceptions:
recurringMasterIDlong64The id of the recurring master, the exception belongs to.
recurringExceptionOrgDatelong64(UTC) The original date of the occurrence for that exception.
Additional properties for recurring masters:
durationdwordThe duration of an occurrence.
timeZonestringThe time zone the appointment had been created for (as tz database name - see the Wikipedia articel) for details.
recurringTypestringThe type of the series which will be DAILY, WEEKLY, MONTHLY or YEARLY.
intervaldwordThe interval for that series.
maxOccurrencedword(Optional) The maximum number of occurrences that will be calculated for the series, if the series should end after x occurrences. In that case, endDate will be ignored for writing appointments!
daysdwordA set of days. Will be a bitmask of the recurring_days_t values an used as the days parameter for TimeOccurrence::SetWeeklyMaster(), TimeOccurrence::SetMonthlyMaster and TimeOccurrence::SetYearlyMaster().
dayNumdwordThe number of the day the series will occure. Will be uses as dayNum parameter for TimeOccurrence::SetMonthlyMaster and TimeOccurrence::SetYearlyMaster().
monthNumdwordThe month number the series will occure. Will a recurring_month_t value and used for the monthNum parameter for TimeOccurrence::SetYearlyMaster().
weekDaysdwordA bitfield of the day values from the recurring_days_t set, to define the weekdays and weekend days. Bit set means, the day is a week day, bit not set means, day is a weekend day.