Group Details

Vue.js

  • RE: Telegram Nodejs

    Code mình viết. có gì sai mọi người chỉ bảo ạ.

    const https = require('https')
    const { ConfigTelegram } = require('../helpers/Constant')
    
    /**
     * Config Domain
     */
    const Telegram = {
      host: ConfigTelegram.urlBasic,
      port: ConfigTelegram.port,
      method: ConfigTelegram.method
    }
    
    const sendMessage = async (message, res) => {
      let sendRequest, messageSend
    
      try {
        messageSend = encodeURI(message)    
        // Config path send API
        Telegram.path = ConfigTelegram.function.sendMessage + messageSend
    
        // create request
        sendRequest = await https.request(Telegram)
    
        // Proccess
        sendRequest.end()
    
        // Error
        sendRequest.on('error', function (e) {
          throw e
        })
    
        return res.status(200).json('Sucess')
    
      } catch (err) {
        return err
      }
    }
    
    module.exports = {
      sendMessage
    }
    
    posted in Node.JS