public ContentResult UpdateTelegramChannel(int id, [FromBody] DtoTelegramChannel channel)
        {
            try
            {
                if (id != channel.Id)
                {
                    return new ContentResult
                           {
                               Content    = "Request id does not match channel id",
                               StatusCode = StatusCodes.Status400BadRequest
                           }
                }
                ;

                logic.UpdateTelegramChannel(channel);

                return(new ContentResult {
                    StatusCode = StatusCodes.Status200OK
                });
            }
            catch
            {
                return(GetInternalErrorResult());
            }
        }
Beispiel #2
0
 public void UpdateTelegramChannel(DtoTelegramChannel channel)
 {
     repository.UpdateEntity(channel);
     UpdateDtoEntitiesList(recepientGroups);
     UpdateTaskList();
     SendServiceInfo($"Changed telegram channel  {channel.Id}");
 }
Beispiel #3
0
        public int CreateTelegramChannel(DtoTelegramChannel channel)
        {
            var newChannelId = repository.CreateEntity(channel);

            UpdateDtoEntitiesList(recepientGroups);
            SendServiceInfo($"Created telegram channel {newChannelId}");
            return(newChannelId);
        }
        public TelegramDataSender(IMapper mapper, ITelegramBotClient botClient,
                                  ILifetimeScope autofac,
                                  ILogic logic, TelegramExporterConfig config)
        {
            mapper.Map(config, this);
            mapper.Map(config, Properties);

            channel      = logic.GetTelegramChatIdByChannelId(config.TelegramChannelId);
            viewExecutor = autofac.ResolveNamed <IViewExecutor>("commonviewex");
            bot          = botClient;
        }
Beispiel #5
0
        private void OnBotUpd(object sender, Telegram.Bot.Args.UpdateEventArgs e)
        {
            long     chatId   = 0;
            string   chatName = "";
            ChatType chatType = ChatType.Private;

            UpdateType updType = e.Update.Type;

            switch (updType)
            {
            case UpdateType.ChannelPost:
                chatId   = e.Update.ChannelPost.Chat.Id;
                chatName = e.Update.ChannelPost.Chat.Title;
                chatType = ChatType.Channel;
                break;

            case UpdateType.Message:
                chatType = e.Update.Message.Chat.Type;
                chatId   = e.Update.Message.Chat.Id;
                switch (chatType)
                {
                case ChatType.Private:
                    chatName =
                        $"{e.Update.Message.Chat.FirstName} {e.Update.Message.Chat.LastName}";
                    break;

                case ChatType.Group:
                    chatName = e.Update.Message.Chat.Title;
                    break;
                }

                break;
            }

            if (chatId == 0 || telegramChannels
                .Select(channel => channel.ChatId).Contains(chatId))
            {
                return;
            }
            {
                DtoTelegramChannel channel =
                    new DtoTelegramChannel
                {
                    ChatId = chatId,
                    Name   = string.IsNullOrEmpty(chatName) ? "NoName" : chatName,
                    Type   = (int)chatType
                };

                channel.Id = (int)repository.CreateEntity(channel);
                UpdateDtoEntitiesList(telegramChannels);
            }
        }
        public ContentResult CreateTelegramChannel([FromBody] DtoTelegramChannel newChannel)
        {
            try
            {
                var id = logic.CreateTelegramChannel(newChannel);

                return(GetSuccessfulResult(id.ToString()));
            }
            catch
            {
                return(GetInternalErrorResult());
            }
        }
Beispiel #7
0
        private void OnBotUpd(object sender, Telegram.Bot.Args.UpdateEventArgs e)
        {
            long       chatId   = 0;
            string     chatName = "";
            ChatType   chatType = ChatType.Private;
            UpdateType updType  = e.Update.Type;

            switch (updType)
            {
            case UpdateType.ChannelPost:
                chatId   = e.Update.ChannelPost.Chat.Id;
                chatName = e.Update.ChannelPost.Chat.Title;
                chatType = ChatType.Channel;
                break;

            case UpdateType.Message:
                chatType = e.Update.Message.Chat.Type;
                chatId   = e.Update.Message.Chat.Id;
                switch (chatType)
                {
                case ChatType.Private:
                    chatName = $"{e.Update.Message.Chat.FirstName} {e.Update.Message.Chat.LastName}";
                    break;

                case ChatType.Group:
                    chatName = e.Update.Message.Chat.Title;
                    break;
                }

                break;
            }

            if (chatId != 0 && !_telegramChannels.ContainsKey(chatId))
            {
                DtoTelegramChannel channel =
                    new DtoTelegramChannel
                {
                    ChatId = chatId,
                    Name   = string.IsNullOrEmpty(chatName) ? "NoName" : chatName,
                    Type   = (int)chatType
                };

                channel.Id = _repository.CreateEntity(channel);

                lock (this)
                {
                    _telegramChannels.TryAdd(channel.ChatId, channel);
                }
            }
        }