• 20-07-2023, 23:44:44
    #1
    Bilmiyorum, belki basit belki de zor bir konu ama akşamdan beri bununla uğraşıyorum, benim için çok zor olduğundan eminim.
    Bir telegram botu oluşturdum ve bu bot A kanalında paylaşılan gönderiyi anında B grubuna iletiyor. Fakat bunu yaparken sadece görsel ile text'i iletiyor, yani gömülü bağlantıları iletmiyor. Bunun için ne yapmalıyım? Kodda gömülü bağlantıları da iletmesini sağlayacağını düşündüğüm bi kod ekledim fakat işe yaramadı, gömülü bağlantıyı text olarak iletiyor. Bilen hocalarımız yardımcı olabilirse çok sevinirim, şimdiden çok teşekkürler. Kod:

    const TelegramBot = require('node-telegram-bot-api');
    const sourceChannelId = CHANNEL_ID;
    const targetChannelId = CHANNEL_ID;
    const bot = new TelegramBot('BOT_TOKEN', { polling: true });
    bot.on('channel_post', (msg) => {
      if (msg.chat.id === sourceChannelId) {
        const chatId = msg.chat.id;
        // Görsel içerik varsa ilet
        if (msg.photo) {
          const photoId = msg.photo[msg.photo.length - 1].file_id;
          bot.sendPhoto(targetChannelId, photoId, { caption: msg.caption });
        }
        // Video içerik varsa ilet
        if (msg.video) {
          const videoId = msg.video.file_id;
          bot.sendVideo(targetChannelId, videoId, { caption: msg.caption });
        }
        // Ses içerik varsa ilet
        if (msg.audio) {
          const audioId = msg.audio.file_id;
          bot.sendAudio(targetChannelId, audioId, { caption: msg.caption });
        }
        // Belge içerik varsa ilet
        if (msg.document) {
          const documentId = msg.document.file_id;
          bot.sendDocument(targetChannelId, documentId, { caption: msg.caption });
        }
        // Gömülü bağlantı varsa ve metin içeriği boş değilse, bağlantıları metin içeriği ile birleştirerek gönder
        if (msg.entities && msg.text) {
          let urls = [];
          for (const entity of msg.entities) {
            if (entity.type === 'text_link') {
              urls.push(entity.url);
            }
          }
          // Gömülü bağlantıları metne ekleyin
          if (urls.length > 0) {
            messageToSend += urls.join('\n');
            messageToSend += '\n\n';
          }
        }
        // Metin içerik varsa ilet
        if (msg.text) {
          bot.sendMessage(targetChannelId, msg.text);
        }
      }
    });
  • 20-07-2023, 23:52:21
    #2
        
    const TelegramBot = require('node-telegram-bot-api');
    const sourceChannelId = CHANNEL_ID;
    const targetChannelId = CHANNEL_ID;
    const bot = new TelegramBot('BOT_TOKEN', { polling: true });
    bot.on('channel_post', (msg) => {
      if (msg.chat.id === sourceChannelId) {
        // Mesajın içeriğini tutmak için bir değişken oluşturun
        let messageToSend = '';
    
        // Görsel içerik varsa ilet
        if (msg.photo) {
          const photoId = msg.photo[msg.photo.length - 1].file_id;
          bot.sendPhoto(targetChannelId, photoId, { caption: msg.caption });
        }
    
        // Video içerik varsa ilet
        if (msg.video) {
          const videoId = msg.video.file_id;
          bot.sendVideo(targetChannelId, videoId, { caption: msg.caption });
        }
    
        // Ses içerik varsa ilet
        if (msg.audio) {
          const audioId = msg.audio.file_id;
          bot.sendAudio(targetChannelId, audioId, { caption: msg.caption });
        }
    
        // Belge içerik varsa ilet
        if (msg.document) {
          const documentId = msg.document.file_id;
          bot.sendDocument(targetChannelId, documentId, { caption: msg.caption });
        }
    
        // Gömülü bağlantı varsa ve metin içeriği boş değilse, bağlantıları metin içeriği ile birleştirerek gönder
        if (msg.entities && msg.text) {
          // İletilecek mesajı alın
          messageToSend += msg.text;
    
          // Gömülü bağlantıları metne ekleyin
          let urls = [];
          for (const entity of msg.entities) {
            if (entity.type === 'text_link') {
              urls.push(entity.url);
            }
          }
          if (urls.length > 0) {
            messageToSend += '\n\n' + urls.join('\n');
          }
        }
    
        // Mesajı gönderin
        if (messageToSend) {
          bot.sendMessage(targetChannelId, messageToSend);
        }
      }
    });

    Bir deneyin.
  • 21-07-2023, 00:00:42
    #3
    bOZi adlı üyeden alıntı: mesajı görüntüle
        
    const TelegramBot = require('node-telegram-bot-api');
    const sourceChannelId = CHANNEL_ID;
    const targetChannelId = CHANNEL_ID;
    const bot = new TelegramBot('BOT_TOKEN', { polling: true });
    bot.on('channel_post', (msg) => {
      if (msg.chat.id === sourceChannelId) {
        // Mesajın içeriğini tutmak için bir değişken oluşturun
        let messageToSend = '';
    
        // Görsel içerik varsa ilet
        if (msg.photo) {
          const photoId = msg.photo[msg.photo.length - 1].file_id;
          bot.sendPhoto(targetChannelId, photoId, { caption: msg.caption });
        }
    
        // Video içerik varsa ilet
        if (msg.video) {
          const videoId = msg.video.file_id;
          bot.sendVideo(targetChannelId, videoId, { caption: msg.caption });
        }
    
        // Ses içerik varsa ilet
        if (msg.audio) {
          const audioId = msg.audio.file_id;
          bot.sendAudio(targetChannelId, audioId, { caption: msg.caption });
        }
    
        // Belge içerik varsa ilet
        if (msg.document) {
          const documentId = msg.document.file_id;
          bot.sendDocument(targetChannelId, documentId, { caption: msg.caption });
        }
    
        // Gömülü bağlantı varsa ve metin içeriği boş değilse, bağlantıları metin içeriği ile birleştirerek gönder
        if (msg.entities && msg.text) {
          // İletilecek mesajı alın
          messageToSend += msg.text;
    
          // Gömülü bağlantıları metne ekleyin
          let urls = [];
          for (const entity of msg.entities) {
            if (entity.type === 'text_link') {
              urls.push(entity.url);
            }
          }
          if (urls.length > 0) {
            messageToSend += '\n\n' + urls.join('\n');
          }
        }
    
        // Mesajı gönderin
        if (messageToSend) {
          bot.sendMessage(targetChannelId, messageToSend);
        }
      }
    });
    Bir deneyin.
    Maalesef hocam, işe yaramadı :/
  • 21-07-2023, 00:09:05
    #4
     
    const TelegramBot = require('node-telegram-bot-api');
    const sourceChannelId = CHANNEL_ID;
    const targetChannelId = CHANNEL_ID;
    const bot = new TelegramBot('BOT_TOKEN', { polling: true });
    bot.on('channel_post', (msg) => {
      if (msg.chat.id === sourceChannelId) {
        // Mesajın içeriğini tutmak için bir değişken oluşturun
        let messageToSend = '';
    
        // Görsel içerik varsa ilet
        if (msg.photo) {
          const photoId = msg.photo[msg.photo.length - 1].file_id;
          bot.sendPhoto(targetChannelId, photoId, { caption: msg.caption });
        }
    
        // Video içerik varsa ilet
        if (msg.video) {
          const videoId = msg.video.file_id;
          bot.sendVideo(targetChannelId, videoId, { caption: msg.caption });
        }
    
        // Ses içerik varsa ilet
        if (msg.audio) {
          const audioId = msg.audio.file_id;
          bot.sendAudio(targetChannelId, audioId, { caption: msg.caption });
        }
    
        // Belge içerik varsa ilet
        if (msg.document) {
          const documentId = msg.document.file_id;
          bot.sendDocument(targetChannelId, documentId, { caption: msg.caption });
        }
    
        // Gömülü bağlantı varsa ve metin içeriği boş değilse, bağlantıları metin içeriği ile birleştirerek gönder
        if (msg.entities && msg.text) {
          // İletilecek mesajı alın
          messageToSend += msg.text;
    
          // Gömülü bağlantıları metne ekleyin
          let urls = [];
          for (const entity of msg.entities) {
            if (entity.type === 'text_link') {
              urls.push(entity.url);
            }
          }
          if (urls.length > 0) {
            messageToSend += '\n\n' + urls.join('\n');
          }
        }
    
        // Metin içerik varsa ve gömülü bağlantılar eklendiyse ilet
        if (msg.text && messageToSend) {
          bot.sendMessage(targetChannelId, messageToSend);
        }
      }
    });

    MessageToSend değişkenini tanimlamamisim. Bir de böyle deneyebilir misin?
  • 21-07-2023, 00:20:37
    #5
    bOZi adlı üyeden alıntı: mesajı görüntüle
    const TelegramBot = require('node-telegram-bot-api');
    const sourceChannelId = CHANNEL_ID;
    const targetChannelId = CHANNEL_ID;
    const bot = new TelegramBot('BOT_TOKEN', { polling: true });
    bot.on('channel_post', (msg) => {
      if (msg.chat.id === sourceChannelId) {
        // Mesajın içeriğini tutmak için bir değişken oluşturun
        let messageToSend = '';
    
        // Görsel içerik varsa ilet
        if (msg.photo) {
          const photoId = msg.photo[msg.photo.length - 1].file_id;
          bot.sendPhoto(targetChannelId, photoId, { caption: msg.caption });
        }
    
        // Video içerik varsa ilet
        if (msg.video) {
          const videoId = msg.video.file_id;
          bot.sendVideo(targetChannelId, videoId, { caption: msg.caption });
        }
    
        // Ses içerik varsa ilet
        if (msg.audio) {
          const audioId = msg.audio.file_id;
          bot.sendAudio(targetChannelId, audioId, { caption: msg.caption });
        }
    
        // Belge içerik varsa ilet
        if (msg.document) {
          const documentId = msg.document.file_id;
          bot.sendDocument(targetChannelId, documentId, { caption: msg.caption });
        }
    
        // Gömülü bağlantı varsa ve metin içeriği boş değilse, bağlantıları metin içeriği ile birleştirerek gönder
        if (msg.entities && msg.text) {
          // İletilecek mesajı alın
          messageToSend += msg.text;
    
          // Gömülü bağlantıları metne ekleyin
          let urls = [];
          for (const entity of msg.entities) {
            if (entity.type === 'text_link') {
              urls.push(entity.url);
            }
          }
          if (urls.length > 0) {
            messageToSend += '\n\n' + urls.join('\n');
          }
        }
    
        // Metin içerik varsa ve gömülü bağlantılar eklendiyse ilet
        if (msg.text && messageToSend) {
          bot.sendMessage(targetChannelId, messageToSend);
        }
      }
    });
    MessageToSend değişkenini tanimlamamisim. Bir de böyle deneyebilir misin?
    Hocam ilginiz için çok teşekkür ederim fakat bu şekilde de görsel dahil olunca değişen bir şey olmuyor, fakat görselsiz paylaşınca da gömülü değil de text + bağlantı şeklinde gösteriyor :/
  • 21-07-2023, 00:26:06
    #6
    Platin üye
    Bu tarz seylere chat gpt cok iyi cevao veriyor. Kodunuzu yapistirin ve derdinizi yazin.
  • 21-07-2023, 00:35:32
    #7
    Micron adlı üyeden alıntı: mesajı görüntüle
    Bu tarz seylere chat gpt cok iyi cevao veriyor. Kodunuzu yapistirin ve derdinizi yazin.
    Dayanamadım sordum:

    Durumunuzun çözümü için kullandığınız kodda başka bir hata olabilir. Sorunu anlamak için birkaç ek adımı takip edebiliriz:
    1. Botunuzun izinleri: Emin olun, botunuzun hedef grubunuza mesaj gönderme izni olduğundan emin olun. Bazen, botlar yalnızca metin tabanlı mesajlar gönderebilir ve diğer içerik türleri için izinleri düzgün ayarlanmamış olabilir.
    2. Botunuzun ve Telegram API sürümünüzün güncelliği: Kullandığınız node-telegram-bot-api sürümü, botunuzun Telegram API'si ile uyumlu olmalıdır. Güncel bir sürüm kullandığınızdan emin olun.
    3. Mesaj nesnesi içeriğini kontrol edin: Kodunuzdaki msg nesnesinin içeriğini kontrol edin ve gömülü bağlantıların doğru bir şekilde yer aldığından emin olun. Gömülü bağlantıların msg.entities özelliği altında olması gerektiğini unutmayın.
    4. Yazdığınız mesajların biçimini inceleyin: Göndermeye çalıştığınız mesajların tam olarak neye benzediğini ve doğru formatta mı gönderildiğini kontrol edin. Belki bir biçimlendirme hatası nedeniyle beklediğiniz sonucu elde edemiyorsunuz.
    Eğer bu adımları takip edip sorununuzun hala çözülmediğini düşünüyorsanız, lütfen kodunuzdaki tüm içeriği ve Telegram botunuzun API versiyonunu gözden geçirerek bana gönderin. Size daha fazla yardımcı olmaya çalışacağım.