public static async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log)
        {
            using (BotService.Initialize())
            {
                var subscriptionFacade = new SubscriptionFacade();
                var reportsFacade      = new ReportsFacade();
                var unavailableDevices = await reportsFacade.GetUnavailableDeviceReports();

                var subscriptions = (await subscriptionFacade.GetAllSubscriptions()).ToArray();

                foreach (var subscription in subscriptions.Where(t => t.LastActivity != null && DateTime.UtcNow.Subtract(t.LastActivity.Created) > TimeSpan.FromDays(1)))
                {
                    var connector = new ConnectorClient(new Uri(subscription.ServiceUrl), Environment.GetEnvironmentVariable("MicrosoftAppId"), Environment.GetEnvironmentVariable("MicrosoftAppPassword"));
                    await connector.Conversations.DeleteActivityAsync(subscription.LastActivity.ConversationId, subscription.LastActivity.ActitityId);

                    subscription.LastActivity = null;
                    await subscriptionFacade.UpdateBotSubscription(subscription);
                }

                foreach (var deviceGroup in unavailableDevices.GroupBy(t => t.Group))
                {
                    var message    = new DeviceStatusMessage(deviceGroup.ToList());
                    var recipients = subscriptions.Where(t => t.GroupName == deviceGroup.Key);
                    await message.SendMessageToChannel("Found unavailable devices!", recipients);
                }
            }
        }
        public async Task SendMessageToChannel(string title, BotSubscription subscription)
        {
            var subscriptionFacade = new SubscriptionFacade();
            var channelData        = new TeamsChannelData
            {
                Channel = new ChannelInfo(subscription.ChannelId),
                Team    = new TeamInfo(subscription.TeamId),
                Tenant  = new TenantInfo(subscription.TenantId)
            };

            var newMessageText = await Build();

            var newMessage = new Activity
            {
                Type = ActivityTypes.Message,
                Text = newMessageText.FixNewLines(),
            };
            var conversationParams = new ConversationParameters(
                isGroup: true,
                bot: null,
                members: null,
                topicName: title,
                activity: (Activity)newMessage,
                channelData: channelData);

            var connector = new ConnectorClient(new Uri(subscription.ServiceUrl), Environment.GetEnvironmentVariable("MicrosoftAppId"), Environment.GetEnvironmentVariable("MicrosoftAppPassword"));

            MicrosoftAppCredentials.TrustServiceUrl(subscription.ServiceUrl, DateTime.MaxValue);

            if (subscription.LastActivity == null)
            {
                var result = await connector.Conversations.CreateConversationAsync(conversationParams);

                subscription.LastActivity = new LastActivity
                {
                    ConversationId = result.Id,
                    ActitityId     = result.ActivityId
                };
            }
            else
            {
                var result = await connector.Conversations.UpdateActivityAsync(subscription.LastActivity.ConversationId, subscription.LastActivity.ActitityId, newMessage);

                subscription.LastActivity.ActitityId = result.Id;
            }

            await subscriptionFacade.UpdateBotSubscription(subscription);
        }