Загрузить файлы в «/»

This commit is contained in:
serov 2025-02-23 09:59:42 +00:00
commit 409ae39297
3 changed files with 117 additions and 0 deletions

7
App.config Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="TelegramBotToken" value="YOUR_BOT_TOKEN" />
<add key="TelegramChannelId" value="YOUR_CHANNEL_ID" />
</appSettings>
</configuration>

View File

@ -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
);
}
}
}

34
ThisAddIn.cs Normal file
View File

@ -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
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}