2016-05-11 46 views
0

テレグラムに写真を送信するためのコードを設定し、まずlocalhostで作業してから、telegram.botパッケージをver 9.0.0に更新し、sever dosenに公開します。 localhostとserverで動作しません。テレグラムのSendPhoto()メソッド

私は、写真の代わりにテキストを送信するためにtry/catchを使用していますが、今は動作していません。つまり、Tryブロックが動作していても効果がありません。ストリーム 例に

 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); 
     } 
    } 

答えて

0

読み出し画像

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(); 
関連する問題