Done! Congratulations on your new bot. You will find it at t.me/kjjkbot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.
Use this token to access the HTTP API:.....
使用Node.js與telegram bot溝通
之後我們使用npm install node-telegram-bot-api --save
然後貼上以下程式碼
var express = require('express');
var bodyParser = require('body-parser');
var util = require('util');
var app = express();
var port = 8000;
var TelegramBot = require('node-telegram-bot-api');
var token = '改為你的token';
//括號裡面的內容需要改為在第5步獲得的Token
var bot = new TelegramBot(token, {polling: true});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post('/payload', (req, res) => {
var obj = req.body.push.changes[0].new;
msgPayload = `${obj.target.author.raw} push 到 ${obj.name} 分支,查看該次commit: ${obj.links.html.href}`
bot.sendMessage(324090896, msgPayload);
})
//Bot
bot.onText(/hihi/, function (msg) {
var chatId = msg.chat.id; //房間ID
var resp = '你好'; //括號裡面的為回應內容,可以隨意更改
console.log(chatId);
bot.sendMessage(chatId, resp); //發送訊息的function
});
app.listen(port,() => console.log(`listening on ${port}`));