commit 409ae39297602840c2793d0bfc4aceb1e821c3cb
Author: serov <1@dmserov.ru>
Date: Sun Feb 23 09:59:42 2025 +0000
Загрузить файлы в «/»
diff --git a/App.config b/App.config
new file mode 100644
index 0000000..ce5349b
--- /dev/null
+++ b/App.config
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OutlookTelegramNotifier.cs b/OutlookTelegramNotifier.cs
new file mode 100644
index 0000000..67e16ee
--- /dev/null
+++ b/OutlookTelegramNotifier.cs
@@ -0,0 +1,76 @@
+using Microsoft.Office.Interop.Outlook;
+using System;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
+using Telegram.Bot;
+
+namespace OutlookTelegramNotifier
+{
+ [ComVisible(true)]
+ public class OutlookTelegramNotifier
+ {
+ private Application outlookApp;
+ private TelegramBotClient botClient;
+ private const string TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN";
+ private const string TELEGRAM_CHANNEL_ID = "YOUR_CHANNEL_ID";
+ private Timer checkTimer;
+
+ public OutlookTelegramNotifier()
+ {
+ outlookApp = Globals.ThisAddIn.Application;
+ botClient = new TelegramBotClient(TELEGRAM_BOT_TOKEN);
+
+ // Запускаем таймер для проверки событий каждую минуту
+ checkTimer = new Timer(CheckUpcomingMeetings, null, 0, 60000);
+ }
+
+ private async void CheckUpcomingMeetings(object state)
+ {
+ try
+ {
+ var calendar = outlookApp.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
+ var items = calendar.Items;
+ items.Sort("[Start]");
+
+ var now = DateTime.Now;
+ var fifteenMinutesFromNow = now.AddMinutes(15);
+
+ foreach (AppointmentItem appointment in items)
+ {
+ if (appointment.Start > now && appointment.Start <= fifteenMinutesFromNow)
+ {
+ // Проверяем, не отправляли ли мы уже уведомление для этой встречи
+ if (!appointment.UserProperties["NotificationSent"]?.Value)
+ {
+ await SendTelegramNotification(appointment);
+
+ // Отмечаем, что уведомление отправлено
+ var prop = appointment.UserProperties.Add("NotificationSent", OlUserPropertyType.olYesNo);
+ prop.Value = true;
+ appointment.Save();
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // Обработка ошибок
+ System.Diagnostics.Debug.WriteLine($"Error: {ex.Message}");
+ }
+ }
+
+ private async Task SendTelegramNotification(AppointmentItem appointment)
+ {
+ var message = $"🔔 Напоминание о встрече\n\n" +
+ $"📅 {appointment.Subject}\n" +
+ $"⏰ Начало: {appointment.Start:HH:mm}\n" +
+ $"📍 {appointment.Location}\n\n" +
+ $"Описание: {appointment.Body.Substring(0, Math.Min(appointment.Body.Length, 100))}...";
+
+ await botClient.SendTextMessageAsync(
+ chatId: TELEGRAM_CHANNEL_ID,
+ text: message
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/ThisAddIn.cs b/ThisAddIn.cs
new file mode 100644
index 0000000..6b61e0a
--- /dev/null
+++ b/ThisAddIn.cs
@@ -0,0 +1,34 @@
+using System;
+using Microsoft.Office.Tools.Outlook;
+
+namespace OutlookTelegramNotifier
+{
+ public partial class ThisAddIn
+ {
+ private OutlookTelegramNotifier notifier;
+
+ private void ThisAddIn_Startup(object sender, System.EventArgs e)
+ {
+ notifier = new OutlookTelegramNotifier();
+ }
+
+ private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
+ {
+ // Cleanup code here
+ }
+
+ #region VSTO generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InternalStartup()
+ {
+ this.Startup += new System.EventHandler(ThisAddIn_Startup);
+ this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file