Ejemplo n.º 1
0
 private static void Events_MessageStatusChangedEvent(object sender, TT.Win.SDK.Events.MessageEventArgs e)
 {
     if (recentSentMsgId == e.MessageData.message_id)
     {
         Console.WriteLine(string.Format("Recent sent message status : {0}", e.MessageData.status));
     }
 }
        private async void Events_MessageReceivedEvent(object sender, TT.Win.SDK.Events.MessageEventArgs e)
        {
            try
            {
                // Retrieve the token of the user who sent the message, and the messageId
                string senderToken = string.IsNullOrEmpty(e.MessageData.sender) ? e.MessageData.sender_token : e.MessageData.sender;
                string messageId   = string.IsNullOrEmpty(e.MessageData.message_id) ? e.MessageData.client_id : e.MessageData.message_id;

                // Retrieve body of the message.  For security reasons, this will not be logged below.
                string body = e.MessageData.body;

                if (string.IsNullOrEmpty(e.MessageData.group_token))
                {
                    // This was an individual (P2P) message from the sender to the recipient
                    eventLog1.WriteEntry(string.Format("P2P message received from sender token {0}.  MessageId is {1}.", senderToken, messageId), EventLogEntryType.Information);
                }
                else
                {
                    // This is a message to a group that the user defined by the API key and secret belongs to
                    string groupToken      = e.MessageData.group_token;
                    string groupMessageLog = string.Format("Group message received from sender token {0}.  MessageId is {1}.  Group token is {2}.", senderToken, messageId, groupToken);

                    // Retrieve metadata associated with the group
                    // This allows a group conversation to tie back to another system, such as a patient record in an EMR
                    try
                    {
                        Dictionary <string, string> metadata = await TT.Win.SDK.Api.Metadata.GetMetadataAsync(groupToken);

                        if (metadata != null && metadata.Count > 0)
                        {
                            groupMessageLog += "\r\nMetadata associated with this group:";
                            foreach (string key in metadata.Keys)
                            {
                                groupMessageLog += string.Format("\r\n{0}: {1}", key, metadata[key]);
                            }
                        }
                        else
                        {
                            groupMessageLog += "\r\nNo Metadata associated with this group";
                        }
                    }
                    catch (Exception ex)
                    {
                        groupMessageLog += "\r\nGroup Metadata not available:  " + ex.Message;
                    }

                    eventLog1.WriteEntry(groupMessageLog, EventLogEntryType.Information);
                }
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry(ex.Message, EventLogEntryType.Error);
            }
        }
Ejemplo n.º 3
0
        private async static void Events_MessageReceivedEvent(object sender, TT.Win.SDK.Events.MessageEventArgs e)
        {
            if (e.MessageData.sender_user == null)
            {
                e.MessageData.sender_user = await TT.Win.SDK.Api.User.GetUserAsync(e.MessageData.sender);
            }
            Console.WriteLine(string.Format("Message received from {0} : {1}", e.MessageData.sender_user.display_name, e.MessageData.body));

            if (e.MessageData.AttachmentsToDownload != null)
            {
                DownloadFile(e.MessageData);
            }
        }