Receiving KIM Messages
There are two entry points in receiving messages from the Ti365 KIM-Clientmodule. The first one will receive new messages from the server of the KIM-Provider and store them in the Ti365-Gateway (fully client side encrypted). The other entry point will receive the stored messages from the Ti365-Gateway.
Attachments
For efficient message handling, the attachments binary data itself is not part of the returned message objects using any of the both entry points. The binary data can be received from the Ti365-Gateway by the attachment id with the method
public getMailAttachment(mailId: string, attachmentId: string): Promise<ArrayBuffer>
Receive new KIM messages from the KIM-Provider
For receiving new messages from the server of the KIM-Provider the method public async fetchNewMails(messageReceiveListener?: MessageReceiveListener): Promise<KimFetchMailResponse>
of the KimClient
is used. It takes an optional MessageReceiveListener
which contains status callbacks of the steps during the fetch process, to be able to inform the user about what is going on. It is not required for receiving KIM messages.
The KimFetchMailResponse
contains an array of all fetched messages as well as an array of error occurred during the fetch-process.
The method can also throw KimClientError
.
const fetchResponse = await kimClient.fetchNewMails();
for(const message of fetchResponse.)
{
const fullMessage = await kimClient.getMailContent(mailInfo.storageId);
for(const attachmentInfo of fullMessage.attachments)
{
const attachmentData = kimClient.getMailAttachment(mailInfo.storageId, attachmentInfo.storageId);
}
}
Receive stored KIM messages from the Ti365-Gateway
To receive stored KIM messages from the Ti365-Gateway the method public listMailInfos(): Promise<KimStoredMailMetadata[]>
is used. This method will return a list of message metadata which includes an id for each message. With the messageId the complete message can be retrieved (per message) with the method public getMailContent(id: string): Promise<KimStoredMail>
. This provides an efficient way of handling stored messages.
const mailInfos = await kimClient.listMailInfos();
for(const mailInfo of mailInfos)
{
const fullMessage = await kimClient.getMailContent(mailInfo.storageId);
for(const attachmentInfo of fullMessage.attachments)
{
const attachmentData = kimClient.getMailAttachment(mailInfo.storageId, attachmentInfo.storageId);
}
}
Reading attachments
const mailInfos = await kimClient.listMailInfos();
for(const mailInfo of mailInfos)
{
const fullMessage = await kimClient.getMailContent(mailInfo.storageId);
for(const attachmentInfo of fullMessage.attachments)
{
const attachmentData = kimClient.getMailAttachment(mailInfo.storageId, attachmentInfo.storageId);
}
}