2016-05-11 13 views
0

Ich setze den Code für das Senden des Fotos an ein Telegramm, zuerst arbeitet an meinem localhost, nach Update des telegram.bot Pakets auf ver 9.0.0 und veröffentlichen, um zu trennen arbeite nicht auf localhost und server.Telegram SendPhoto() Methode in ASP.NET von Telegram Bot

Ich benutze die Try/catch für das Senden von Text anstelle von Foto und jetzt funktionieren sie nicht, es ist meine Try Block funktioniert, aber es kann nicht wirken.

 if (offerListDetail != null) 
    { 
     StringBuilder botTextA2 = new StringBuilder(); 
     StringBuilder botTextB2 = new StringBuilder(); 

     string remoteImgPath = offerListDetail.OFL_OfferImageUrl; 
     Uri remoteImgPathUri = new Uri(remoteImgPath); 
     string remoteImgPathWithoutQuery = remoteImgPathUri.GetLeftPart(UriPartial.Path); 
     string fileName = Path.GetFileName(remoteImgPathWithoutQuery); 
     string localPath = Server.MapPath("~/Images/telegram/"); //AppDomain.CurrentDomain.BaseDirectory + "Images/telegram/" + fileName; 
     WebClient webClient = new WebClient(); 
     webClient.DownloadFile(remoteImgPath, localPath + fileName); 

     var botphoto = new FileToSend() 
     { 
      Content = OpenFile(localPath + fileName), 
      Filename = fileName 
     }; 

     //var botClient = new Telegram.Bot.Api("157612108:AAFr4y7WWT32xX41EMOVkmEW19pIgcHImv4"); // استانبولیار 
     var botClient = new Telegram.Bot.Api("186221188:AAHrihjOH7__4vlF0DCNWLEzYQ3p3ORO0_k"); // ربات ری را 
     try 
     { 
      botTextA2.AppendLine(" http://order.reera.ir/offers.aspx?offer=" + offerListDetail.OFL_ID); 
      botTextA2.AppendLine(" " + offerListDetail.OFL_OfferName); 
      botTextA2.AppendLine(" " + offerListDetail.brn_Name); 
      botTextA2.AppendLine(" مهلت " + offerListDetail.remainday + " روز"); 
      botTextA2.AppendLine(" سفارش در http://order.reera.ir"); 
      botTextA2.AppendLine(" یا تلگرام @reerabrand"); 
      string botTextA = botTextA2.ToString().Replace(Environment.NewLine, "\n"); 

      botClient.SendPhoto("@istanbulyar", botphoto, "ddd");//botTextA); 
      botClient.SendPhoto("@reera", botphoto, "ddd");//botTextA); 
     } 
     catch 
     { 
      botTextB2.AppendLine(offerListDetail.OFL_OfferImageUrl); 
      botTextB2.AppendLine("*********************************"); 
      botTextB2.AppendLine("<b> حراجی " + offerListDetail.OFL_OfferName + "</b> "); 
      botTextB2.AppendLine("<i> توسط وبسایت " + offerListDetail.brn_Name + "</i> "); 
      botTextB2.AppendLine(" <b>مهلت خرید تا " + offerListDetail.remainday + " روز دیگر</b> "); 
      botTextB2.AppendLine(" <a href='http://order.reera.ir/offers.aspx?offer=" + offerListDetail.OFL_ID + "'> مشاهده بوتیک </a> "); 
      botTextB2.AppendLine(""); 
      botTextB2.AppendLine(" سفارش در http://order.reera.ir"); 
      botTextB2.AppendLine(" یا تلگرام @reerabrand"); 
      string botTextB = botTextB2.ToString().Replace(Environment.NewLine, "\n"); 

      botClient.SendTextMessage("@istanbulyar", botTextB, parseMode: ParseMode.Html); 
      botClient.SendTextMessage("@reera", botTextB, disableNotification: true, parseMode: ParseMode.Html); 
     } 
    } 

Antwort

0

Lese Bild mit Strom Beispiel

string pic = "نام عکس مورد نظر"; 
string yourpath = Environment.CurrentDirectory + @"\Pic\"+pic; 
FileStream stream = new FileStream(yourpath, FileMode.Open, FileAccess.Read); 
FileToSend fs = new FileToSend("photo3.jpg",stream); 
bot.MakeRequestAsync(new SendPhoto(update.Message.Chat.Id, fs)).Wait(); 
Verwandte Themen