Rocketchat -> telegram

Hey Guys, I am the idiot who wrote the terrible integration for telegram, i am obviously not a programmer but somehow managed to get this working. I am here to ask the people who actually do know what they are doing to update the telegram integration, to have more features.

class Script {
    process_incoming_request({ request }) {
        // UNCOMMENT THE BELOW LINE TO DEBUG IF NEEDED.
        console.log(request.content);
        if ('edited_message' in request.content) {
            request.content.message = request.content.edited_message;
        }
        let who = request.content.message.from.username
        let icon_url = '/avatar/' + request.content.message.from.username + '.jpg'
        if(!who)  {
          who = `${request.content.message.from.first_name} ${request.content.message.from.last_name}`
          icon_url = `/avatar/${request.content.message.from.first_name}.jpg`
        }
        let body = request.content.message.text
        //let photo = request.content.message.attachments.image_url

        //if(!body) {
        //  if(request.content.message.sticker.emoji) {
        //    // It's a sticker
        //    body = request.content.message.sticker.emoji
        //} else {
        //   return {}
        //  }
        //}

        if(request.content.message.sticker) {
          if(request.content.message.sticker.emoji) {
            // It's a sticker
            body = request.content.message.sticker.emoji
        } else {
           return {}
          }
        }
        if(request.content.message.document) {
          if(request.content.message.document) {
            // It's a sticker
            body = 'I send a gif :guenna:' 
        } else {
           return {}
          }
        }
        if(request.content.message.photo) {
          console.log(request.content.message.photo);
          if(request.content.message.photo[0]) {
            // It's a sticker
            //// 'https://api.telegram.org/bot434433230:AAFc4-HZQJDApkMIS3KZR4ankoPYhbLx8bw/getFile?file_id=${request.content.message.photo[0].file_path}'
            //body = 'i uploaded a pic ' + ' ![photo]('+`https://api.telegram.org/file/bot434433230:AAFc4-HZQJDApkMIS3KZR4ankoPYhbLx8bw/${request.content.message.photo[0].file_path}`+')'
            body = 'i uploaded a pic'
            //body = 'https://api.telegram.org/file/bot434433230:AAFc4-HZQJDApkMIS3KZR4ankoPYhbLx8bw/'+`${request.content.message.photo[0].file_path}`
            //request.content.message.attachments.image_url = `https://api.telegram.org/file/bot434433230:AAFc4-HZQJDApkMIS3KZR4ankoPYhbLx8bw/${request.content.message.photo[0].file_path}`
        } else {
           return {}
          }
        }
        if(request.content.message.video) {
          if(request.content.message.video.file_id) {
            // It's a sticker
            // works body = `https://api.telegram.org/file/bot434433230:AAFc4-HZQJDApkMIS3KZR4ankoPYhbLx8bw/${request.content.message.photo[0].file_path}`
            body = 'video upload'
            //request.content.message.attachments.image_url = `https://api.telegram.org/file/bot434433230:AAFc4-HZQJDApkMIS3KZR4ankoPYhbLx8bw/` + ${request.content.message.photo[0].file_path}
        } else {
           return {}
          }
        }
        return {
            content: {
                username: who,
                icon_url: icon_url,
                text: body
            }
        };
    }
}

Right now with every media that someone sends in the telegram channel you’ll receive simple replacements such as this maybe someone can write a better version. Cheers
image

Thank you bott0r for your work.

The integration is working well for me. There is only one thing I have noticed and I am not sure whether this is something that could be improved or whether I am just doing (or have done) something wrong:

When someone posts and quotes an earlier post on Telegram, the new post is copied over to RC but not the quote of the earlier post.

Have you - or has anyone else - experienced this as well and this there something I can do to have the quote copied over, too?

Thanks!