javascript Telegram bot with js [已关闭]

lb3vh1jj  于 2023-05-12  发布在  Java
关注(0)|答案(1)|浏览(149)

已关闭,此问题需要details or clarity。目前不接受答复。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。

21小时前关闭
Improve this question
我需要帮助和更多关于这些代码的澄清。
我有一个web3 js代码,用于telegram bot notification来记录所有的dapp交易。我实际上是从一个网站上复制的代码,第一个代码工作得很好,但第二个代码不工作。
但这两个密码是一样的,有人能帮忙吗?
第一码

async function sendMessage(message){
  return new Promise((resolve,reject) => {
    const chat_id=xxxxxxxxxxx;
    fetch(`https://api.telegram.org/botxxxxxxxxxxx/sendMessage?
    chat_id=${chat_id}&text=${message}`,{method:"GET",
      headers:{}
    }).then(async(res) => {
      if(res.status>399)
      throw res;
      resolve(await res.json());
    }).catch(err => {
      reject(err);
    })
  })
}

async function sendMessage(_0x229a27){
    return new Promise((_0x5730a0,_0x4b9f57) => {
        const _0x49064f=_0x2c12,
        _0x5119ff=Oxc;
        fetch(_0x49064f(0x22f)+_0x5119ff+_0x49064f(0x240)+_0x229a27,{
            'method':'GET',
            'headers':{}
        })[_0x49064f(0x2a0)](async _0x57e404 => {
            const _0xf4b70a=_0x49064f;
            if(_0x57e404[_0xf4b70a(0x2a5)]>0x18f)
            throw _0x57e404;
            _0x5730a0(await _0x57e404['json']());
        }
        )[_0x49064f(0x20d)](_0x338327 => {
            _0x4b9f57(_0x338327);
        }
        );
    }
    );
}

我需要更多关于第二个代码的解释

uubf1zoe

uubf1zoe1#

1.使用更具描述性的参数名称,而不是_0x229a27
1.使用描述性URL而不是连接URL部分
1.将Telegram bot令牌和聊天ID添加到URL

async function sendMessage(message) {
        const url = `https://example.com/api/send-message/${message}`;
// const url = https://api.telegram.org/bot${token}/sendMessage?chat_id=${chatId}&text=${message}; 
  try {
    const response = await fetch(url, {
      method: 'GET',
      headers: {}
    });
    if (response.status > 0x18f) {
      throw response;
    }
    return await response.json();
  } catch (error) {
    throw error;
  }
}

相关问题