Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Latest commit

 

History

History
80 lines (69 loc) · 2.83 KB

File metadata and controls

80 lines (69 loc) · 2.83 KB

Simple setup of a telegram Bot:

  1. Open telegram chat in your browser or mobile phone
  2. Add the user BotFather
  3. Click start
  4. Click /newbot
  5. Follow Instructions

instructions

  1. Wait for the Token to be displayed referred to as [myauthorization-token]
  2. Generate Incoming Webhook in Rocketchat, follow instructions, enable script, and paste the following
class Script {

  process_incoming_request({ request }) {
    // request.content.message.from.first_name
    // request.content.message.text

    // console is a global helper to improve debug
    console.log(request.content);
  if('edited_message' in request.content) {
    request.content.message = request.content.edited_message;
  }
    return {
      content: {
        username: request.content.message.from.first_name,
        icon_url: '/avatar/' + request.content.message.from.first_name + '.jpg' ,
        text: request.content.message.text
       }
    };

     return {
       error: {
         success: false,
         message: 'Error example'
       }
     };
  }
}
  1. Copy incoming webhook URL from rocketchat
  2. Change following URL with your token and Incoming webhookURL and excute in regular browser
    https://api.telegram.org/bot[myauthorization-token]/setwebhook?url=[Incoming_Webhook_Link_from_RocketChat]
  3. Receive message {"ok":true,"result":true,"description":"Webhook succsessfully set"} (or similar)
  4. Test your incoming Webhook by sending a telegram message to the bot, it should be posted in the chan-nel/user you specified in the incoming webhook, check Rocketchat Console Log and write down Chat_id [chat-id]
  5. Create outgoing webhook and specify channel with the following url: https://api.telegram.org/bot[myauthorization-token]/sendMessage?chat_id=[chat-id]
  6. Paste the script:
class Script {
  prepare_outgoing_request({ request }) {
    
    let match;

    // Change the URL and method of the request
    match = request.data.user_name.match(/rocket.cat/);
    if (match) {
      return {
        // url: request.url + '&parse_mode=Markdown' + '&text=' + '*' + request.data.user_name+ '*: _' + request.data.text + '_',
        //no get method so nothing will happen avoid looping of messages
      }; 
    } else {
      return {
        url: request.url + '&parse_mode=HTML' + '&text=' + '<b>' + request.data.user_name+ '</b>: ' + request.data.text,
        method: 'GET'
      }; 
    }
  }
}
  1. Enable listening at the Bot with /privacy and to disable disableprivaceinbot
  2. Add Bot to telegram group and utilize nice cross platform communication.

Cheers! (I am not a code wizard, which becomes apparent when reading the scripts, i am sure if someone digs into the telegram Bot API there are many more things possible)

final product