当前位置: 首页>>代码示例>>C#>>正文


C# Api.GetFile方法代码示例

本文整理汇总了C#中Api.GetFile方法的典型用法代码示例。如果您正苦于以下问题:C# Api.GetFile方法的具体用法?C# Api.GetFile怎么用?C# Api.GetFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Api的用法示例。


在下文中一共展示了Api.GetFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        static async Task Run()
        {
            var Bot = new Api("Your Api Key");

            var me = await Bot.GetMe();

            Console.WriteLine("Hello my name is {0}", me.Username);

            var offset = 0;

            while (true)
            {
                var updates = await Bot.GetUpdates(offset);

                foreach (var update in updates)
                {
                    if (update.Message.Type == MessageType.TextMessage)
                    {
                        await Bot.SendChatAction(update.Message.Chat.Id, ChatAction.Typing);
                        await Task.Delay(2000);
                        var t = await Bot.SendTextMessage(update.Message.Chat.Id, update.Message.Text);
                        Console.WriteLine("Echo Message: {0}", update.Message.Text);
                    }

                    if (update.Message.Type == MessageType.PhotoMessage)
                    {
                        var file = await Bot.GetFile(update.Message.Photo.LastOrDefault()?.FileId);

                        Console.WriteLine("Received Photo: {0}", file.FilePath);

                        var filename = file.FileId+"."+file.FilePath.Split('.').Last();

                        using (var profileImageStream = File.Open(filename, FileMode.Create))
                        {
                            await file.FileStream.CopyToAsync(profileImageStream);
                        }
                    }

                    offset = update.Id + 1;
                }

                await Task.Delay(1000);
            }
        }
开发者ID:carriercomm,项目名称:telegram.bot.examples,代码行数:44,代码来源:Program.cs

示例2: Run

        static async Task Run()
        {
            var Bot = new Api(TokenUrl);

            var me = await Bot.GetMe();

            Console.WriteLine("Hello my name is {0}", me.Username);

            var offset = 0;

            while (true)
            {
                var updates = await Bot.GetUpdates(offset);

                foreach (var update in updates)
                {
                    if (update.Message.Type == MessageType.TextMessage)
                    {
                        await Bot.SendChatAction(update.Message.Chat.Id, ChatAction.Typing);
                        await Task.Delay(2000);

                        var splitMessage = update.Message.Text.Trim().Split(' ');

                        if (splitMessage.Length != 0 && splitMessage[0] == "budget")
                        {
                            try
                            {
                                float newBudget = float.Parse(splitMessage[1]);
                                budget = newBudget;
                                //redis.Set("budget", newBudget);
                            }
                            catch (Exception e)
                            {
                                Exception ex = e;
                            }
                        }
                        else if (splitMessage.Length != 0 && splitMessage[0] == "list")
                        {
                            var filterUser = splitMessage.Length == 2 ? splitMessage[1].Trim() : string.Empty;
                            
                            var outputString = new System.Text.StringBuilder();
                            if(s_expenses.Count == 0)
                            {
                                var tEmpty = await Bot.SendTextMessage(update.Message.Chat.Id, "No expenses recorded.");
                            }
                            else
                            {
                                foreach (var item in s_expenses)
                                {
                                    if(string.IsNullOrEmpty(filterUser) || item.User == filterUser)
                                    {
                                        var reply = string.Format("{0}: £{1} - ({2})", item.Timestamp.ToShortDateString(), item.Cost, item.Category);
                                        outputString.AppendLine(reply);
                                    }                                    
                                }

                                var t = await Bot.SendTextMessage(update.Message.Chat.Id, outputString.ToString());
                            }                            
                        }
                        else
                        {
                            try
                            {
                                var item = BudgetItem.Parse(update.Message.From.FirstName, update.Message.Text, DateTime.Now);
                                s_expenses.Add(item);
                                
                                budget -= item.Cost;
                            }
                            catch
                            {
                                var failResponse = await Bot.SendTextMessage(update.Message.Chat.Id, "Bad entry.  Try again.");
                                Console.WriteLine("Echo Message: {0}", failResponse);
                            }

                            var reply = string.Format("Budget: £{0}", budget);
                            var t = await Bot.SendTextMessage(update.Message.Chat.Id, reply);
                            Console.WriteLine("Echo Message: {0}", update.Message.Text);
                        }                        
                    }

                    if (update.Message.Type == MessageType.PhotoMessage)
                    {
                        var file = await Bot.GetFile(update.Message.Photo.LastOrDefault()?.FileId);

                        Console.WriteLine("Received Photo: {0}", file.FilePath);

                        var filename = file.FileId+"."+file.FilePath.Split('.').Last();

                        using (var profileImageStream = File.Open(filename, FileMode.Create))
                        {
                            await file.FileStream.CopyToAsync(profileImageStream);
                        }
                    }

                    offset = update.Id + 1;
                }

                await Task.Delay(1000);
            }
        }
开发者ID:mohammaddabiri,项目名称:BudgetBot,代码行数:100,代码来源:Program.cs

示例3: Run

        static async Task Run() 
        //static async void Run()
        {//Change
            var Bot = new Api("139410021:AAHoQsUYiH_NiHV0vutnDWSLy1JEslIibz0");

            var me = await Bot.GetMe();

            Console.WriteLine("Hello my name is {0}", me.Username);

            var offset = 0;

            //SQLiteConnection con = new SQLiteConnection();
            //SQLiteCommand com = new SQLiteCommand();
            SqlConnection con = new SqlConnection();
            SqlCommand com = new SqlCommand();
            int userId, courseId, messageId = 0;
            while (true)
            {
                messageId = (int)DataAccessSql.executeScalar(new SqlCommand("SELECT MAX(MESSAGEID) FROM TelegramUpdate"));
                var updates = await Bot.GetUpdates(offset: 0);
               
                Telegram.Bot.Types.Update upd;
                upd = new Telegram.Bot.Types.Update();
                com.Connection = con;
                //con.ConnectionString = @"data source=C:\Users\Administrator\Documents\Visual Studio 2015\Projects\telegram.bot\Telegram.Bot.Echo\db\telegramcontacts.sqlite;
                //   Pooling=true;FailIfMissing=false;Version=3";
                con.ConnectionString = returnConnection(1);
                com.CommandText = @"INSERT INTO TelegramUpdate (Id, messageText, ChatId, ChatFirstName, ChatLastName, ChatUserName, Date, FromFirstName,FromLastName, FromUserName, FromId, MessageId, MessageType)
                                    VALUES(@Id, @messageText, @ChatId, @ChatFirstName, @ChatLastName, @ChatUserName, @Date, @FromFirstName, @FromLastName, @FromUserName, @FromId, @MessageId, @MessageType)";
                //,(botUpdate.Id,botUpdate.message.Text,botUpdate.message.chat.Id,botUpdate.chat.first_name,botUpdate.chat.Laset_name,)";

                foreach (var update in updates)
                {
                    upd = update;
                    if (upd.Message.MessageId > messageId)
                    {
                        try
                        {
                            com.Parameters.Clear();
                            com.Parameters.AddWithValue("Id", upd.Id);
                            com.Parameters.AddWithValue("messageText", upd.Message.Text);
                            com.Parameters.AddWithValue("ChatId", upd.Message.Chat.Id);
                            com.Parameters.AddWithValue("ChatFirstName", upd.Message.Chat.FirstName);
                            com.Parameters.AddWithValue("ChatLastName", "upd.Message.Chat.LastName");
                            com.Parameters.AddWithValue("ChatUserName", upd.Message.Chat.FirstName);
                            com.Parameters.AddWithValue("Date", upd.Message.Date);
                            com.Parameters.AddWithValue("FromFirstName", upd.Message.From.FirstName);
                            com.Parameters.AddWithValue("FromLastName", "upd.Message.From.LastName");
                            com.Parameters.AddWithValue("FromUserName", "upd.Message.From.Username");
                            com.Parameters.AddWithValue("FromId", upd.Message.From.Id);
                            com.Parameters.AddWithValue("MessageId", upd.Message.MessageId);
                            com.Parameters.AddWithValue("MessageType", upd.Message.Type.ToString());
                            com.Connection.Open();
                            com.ExecuteNonQuery();
                            messageId = upd.Message.MessageId;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message + ' ' + System.DateTime.Now.ToString());
                        }
                        finally
                        {
                            com.Connection.Close();
                        }
                    }

                    if (update.Message.Type == MessageType.PhotoMessage)
                    {
                        var file = await Bot.GetFile(update.Message.Photo.LastOrDefault()?.FileId);

                        Console.WriteLine("Received Photo: {0}", file.FilePath);

                        var filename = file.FileId + "." + file.FilePath.Split('.').Last();

                        using (var profileImageStream = File.Open(filename, FileMode.Create))
                        {
                            await file.FileStream.CopyToAsync(profileImageStream);
                        }
                    }

                    offset = update.Id + 1;
                }

                //await Task.Delay(1000);
                offset++;
            }
        }
开发者ID:arghand,项目名称:TelegramBot,代码行数:87,代码来源:Program.cs


注:本文中的Api.GetFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。