/// <summary> /// Check the DiScribe bot email inbox for Webex invite emails created by scheduling /// from Webex.com or from DiScribe web. /// </summary> /// <param name="appConfig"></param> /// <returns></returns> private static async Task <object?> CheckForEmails(IConfigurationRoot appConfig) { MeetingInfo meetingInfo = null; try { var email = await EmailListener.GetEmailAsync(); meetingInfo = MeetingController.HandleEmail(email.Body.Content.ToString(), email.Subject, "", appConfig); await EmailListener.DeleteEmailAsync(email); } catch (Exception emailEx) { Console.Error.WriteLine($">\tCould not read bot invite email. Reason: {emailEx.Message}"); return(null); } if (meetingInfo != null) { Console.WriteLine($">\tNew Meeting Found at: {meetingInfo.StartTime.ToLocalTime()}"); /*Send an audio registration email enabling all unregistered users to enroll on DiScribe website */ MeetingController.SendEmailsToAnyUnregisteredUsers(meetingInfo.AttendeesEmails, appConfig["DB_CONN_STR"]); Console.WriteLine($">\tScheduling dialer to dial in to meeting at {meetingInfo.StartTime}"); //Kay: According to Oloff, this should not have an "await" in front, otherwise it will wait until the meeting finish before checking the inbox again. SchedulerController.Schedule(Run, meetingInfo, appConfig, meetingInfo.StartTime);//Schedule dialer-transcriber workflow as separate task } return(meetingInfo); }
public Application() { LoggingListener logger = new LoggingListener(_fileName, "sdkjdgl"); var editor = new Editor(""); editor.GetManager.Subscribe(logger); var emailAlers = new EmailListener("*****@*****.**", "Someone has changed the file: % s"); editor.GetManager.Subscribe(emailAlers); }
/// <summary> /// Handles meeting invite and returns a MeetingInfo object representing the meeting. /// Webex invites are ignored /// </summary> /// <param name="inviteEvent"></param> /// <param name="appConfig"></param> /// <returns></returns> public static async Task <Meeting.MeetingInfo> HandleInvite(Microsoft.Graph.Event inviteEvent, IConfigurationRoot appConfig) { /*If invite is a Webex invite, ignore the event. We are only interested in Outlook invites */ if (EmailListener.IsValidWebexInvitation(inviteEvent)) { return(null); } /*Here, a new meeting is created * at the time requested in the event received. Metadata can be obtained from the event * in this case.*/ else { MeetingInfo meetingInfo = new MeetingInfo { HostInfo = new WebexHostInfo(appConfig["WEBEX_EMAIL"], appConfig["WEBEX_PW"], appConfig["WEBEX_ID"], appConfig["WEBEX_COMPANY"], appConfig["HOST_TIMEZONE"]) }; /*Get start and end time in original time zone from the Graph event */ DateTime meetingStartOrigin = DateTime.Parse(inviteEvent.Start.DateTime); DateTime meetingEndOrigin = DateTime.Parse(inviteEvent.End.DateTime); var originTimeZone = inviteEvent.Start.TimeZone; /*Calculate meeting duration */ var meetingDuration = meetingEndOrigin.Subtract(meetingStartOrigin); string meetingDurationStr = meetingDuration.TotalMinutes.ToString(); /*Convert start time to the WebEx host's time zone */ DateTime webexStartTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(meetingStartOrigin, originTimeZone, appConfig["HOST_TIMEZONE"]); var attendeeNames = EmailListener.GetAttendeeNames(inviteEvent); var attendeeEmails = EmailListener.GetAttendeeEmails(inviteEvent).Distinct().ToList(); /*Remove the bot email, as the bot must not receive another event. */ foreach (var curEmail in attendeeEmails) { if (curEmail.Equals(appConfig["BOT_Inbox"], StringComparison.OrdinalIgnoreCase)) { attendeeEmails.Remove(curEmail); break; } } meetingInfo = CreateWebexMeeting(inviteEvent.Subject, attendeeNames, attendeeEmails, webexStartTime, meetingDurationStr, meetingInfo.HostInfo, inviteEvent.Organizer.EmailAddress); return(meetingInfo); } }
/// <summary> /// Handles a Webex invite email. Creates MeetingInfo object /// containing metadata about this meeting. /// </summary> /// <param name="emailBody"></param> /// <param name="appConfig"></param> /// <returns></returns> public static MeetingInfo HandleEmail(string emailBody, string emailSubject, string organizerEmail, IConfigurationRoot appConfig) { var hostInfo = new WebexHostInfo(appConfig["WEBEX_EMAIL"], appConfig["WEBEX_PW"], appConfig["WEBEX_ID"], appConfig["WEBEX_COMPANY"]); if (EmailListener.IsValidWebexInvitation(emailBody)) { var meetingInfo = EmailListener.GetMeetingInfoFromWebexInvite(emailBody, emailSubject, hostInfo); meetingInfo.AttendeesEmails = MeetingController.GetAttendeeEmails(meetingInfo); return(meetingInfo); } return(null); }
/// <summary> /// Listens for MS graph events occuring as a result of a meeting invite from Outlook. /// The bot schedules a Webex meeting if a valid meeting invite event is detected. /// </summary> /// <param name="appConfig"></param> /// <returns></returns> private static async Task <object?> CheckForGraphEvents(IConfigurationRoot appConfig) { MeetingInfo meetingInfo = null; Microsoft.Graph.Event inviteEvent; try { /*Attempt to get. latest event from bot's Outlook account. * If there are no events, nothing will be scheduled. */ inviteEvent = await EmailListener.GetEventAsync(); await EmailListener.DeleteEventAsync(inviteEvent); /*Handle the invite. * Assign the returned meeting info about the scheduled meeting or * null if this is not an Outlook invite*/ meetingInfo = await MeetingController.HandleInvite(inviteEvent, appConfig); } catch (Exception ex) { //throw new Exception($"Could not get any MS Graph events. Reason: {ex.Message}"); Console.WriteLine($">\tCould not get any MS Graph events. Reason: {ex.Message}"); return(null); } if (meetingInfo != null) { Console.WriteLine($">\tNew Meeting Found at: {meetingInfo.StartTime}"); /*Send an audio registration email enabling all unregistered users to enroll on DiScribe website */ MeetingController.SendEmailsToAnyUnregisteredUsers(meetingInfo.AttendeesEmails, appConfig["DB_CONN_STR"]); Console.WriteLine($">\tScheduling dialer to dial in to meeting at {meetingInfo.StartTime}"); /*Convert start time and end time to the DiScribe bot time zone from the Webex host's time zone */ var botStartTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(meetingInfo.StartTime, meetingInfo.HostInfo.TimeZone, TimeZoneInfo.Local.Id); //Kay: According to Oloff, this should not have an "await" in front, otherwise it will wait until the meeting finish before checking the inbox again. SchedulerController.Schedule(Run, meetingInfo, appConfig, meetingInfo.StartTime);//Schedule dialer-transcriber workflow as separate task } return(meetingInfo); }
public void Run() { Editor editor = new Editor(); LoggingListener l = new LoggingListener("log.txt", "Message ->"); editor.em.Subscribe("open", l); editor.OpenFile("1.txt"); EmailListener e = new EmailListener("*****@*****.**", "Hello,"); editor.em.Subscribe("save", e); editor.em.Subscribe("save", l); editor.SaveFile(); System.Console.WriteLine("Deleted listener"); editor.em.Unsubscribe("save", l); editor.SaveFile(); }
public static async Task Execute() { Console.WriteLine(">\tDiScribe Initializing..."); // Set Authentication configurations var appConfig = Configurations.LoadAppSettings(); EmailListener.Initialize( appConfig["appId"], // appConfig["tenantId"], appConfig["clientSecret"], appConfig["BOT_Inbox"] // bot's email account ).Wait(); MeetingController.BOT_EMAIL = appConfig["BOT_Inbox"]; int graphApiDelayInterval = int.Parse(appConfig["graphApiDelayInterval"]); /*Main application loop */ while (true) { Console.WriteLine(">\tBot is Listening for meeting invites..."); try { StartInvitationListening(appConfig, graphApiDelayInterval).Wait(); } catch (AggregateException exs) { foreach (var ex in exs.InnerExceptions) { Console.Error.WriteLine($">\t{ex.Message}"); } } finally { await Task.Delay(graphApiDelayInterval * 1000); } } }
/// <summary> /// Creates a webex meeting with the specified parameters. Note that duration is in minutes. /// </summary> /// <param name="meetingSubject"></param> /// <param name="names"></param> /// <param name="emails"></param> /// <param name="duration"></param> /// <param name="hostInfo"></param> /// <returns></returns> public static MeetingInfo CreateWebexMeeting(string meetingSubject, List <string> names, List <string> emails, DateTime startTime, string duration, WebexHostInfo hostInfo, Microsoft.Graph.EmailAddress delegateEmail) { string strXMLServer = "https://companykm.my.webex.com/WBXService/XMLService"; WebRequest request = WebRequest.Create(strXMLServer); // Set the Method property of the request to POST. request.Method = "POST"; // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Create POST data and convert it to a byte array. // string strXML = GenerateXMLCreateMeeting(); string formattedStartTime = startTime.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture); string strXML = XMLHelper.GenerateMeetingXML(meetingSubject, names, emails, formattedStartTime, duration, hostInfo, delegateEmail); //string strXML = XMLHelper.GenerateMeetingXML(meetingSubject, names, emails, formattedStartTime, duration, hostInfo); byte[] byteArray = Encoding.UTF8.GetBytes(strXML); // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. string accessCode = XMLHelper.RetrieveAccessCode(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); Console.WriteLine("\tMeeting has been successfully created"); var endTime = startTime.AddMinutes(double.Parse(duration)); /*Convert email list to Sendgrid email objects */ var sendGridEmails = EmailListener.ParseEmailList(emails); /*Store meeting record in database for the created meeting */ var meeting = DatabaseController.CreateMeeting(emails, startTime, endTime, accessCode, meetingSubject); MeetingInfo meetingInfo = new MeetingInfo(meeting, sendGridEmails, "", hostInfo); /*Send an email to allow host or delegates to start the meeting */ EmailSender.SendEmailForStartURL(meetingInfo, new EmailAddress(delegateEmail.Address, delegateEmail.Name)); return(meetingInfo); }