Ejemplo n.º 1
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.

        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            //string text = context.GetValue(this.Text);

            TelegramProp telegramDetails = (TelegramProp)context.DataContext.GetProperties()["telegramDetails"].GetValue(context.DataContext);

            var botToken = telegramDetails.authToken;

            var messageText = MessageText.Get(context);

            if (messageText == null)
            {
                throw new ArgumentException("MesageText missing");
            }

            var chatID = ChatID.Get(context);

            var chatID_str = Convert.ToString(chatID);

            if (chatID_str == null)
            {
                throw new ArgumentException("Chat-ID missing");
            }


            var botClient = new TelegramBotClient(botToken);

            Message message = botClient.SendTextMessageAsync(chatID, messageText).GetAwaiter().GetResult();
        }
Ejemplo n.º 2
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.

        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            //string text = context.GetValue(this.Text);

            TelegramProp telegramDetails = (TelegramProp)context.DataContext.GetProperties()["telegramDetails"].GetValue(context.DataContext);

            var botToken = telegramDetails.authToken;

            var photopath = PhotoPath.Get(context);

            if (photopath == null)
            {
                throw new ArgumentException("Photo-Path missing");
            }

            var chatID = ChatID.Get(context);

            var chatID_str = Convert.ToString(chatID);

            if (chatID_str == null)
            {
                throw new ArgumentException("Chat-ID missing");
            }

            var image_text = Image_Text.Get(context);

            if (image_text == null)
            {
                image_text = "Image sent from Bot";
            }

            var botClient = new TelegramBotClient(botToken);

            string file = photopath;

            var fileName = file.Split(Path.DirectorySeparatorChar).Last();

            using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                Message Photo = botClient.SendPhotoAsync(chatID, fileStream, image_text).GetAwaiter().GetResult();
            }
        }