0
如何將新Telegram Bot用戶插入到CouchDB?
我插入一個樣本數據jack johns
在分貝和是好的,但我不知道我應該如何採取電報用戶的用戶名並把它放在Db。 這是我的代碼:電報機器人和CouchDB將新用戶插入數據庫
import 'babel-polyfill';
import './env';
import TelegramBot from 'node-telegram-bot-api';
const bot = new TelegramBot(process.env.BOT_TOKEN, {polling: true});
/////////////////////////////////// Sample Data
var server = require('couch-db')('http://localhost:5984');
var db = server.database('users');
db.destroy(function(err) {
// create a new database
db.create(function(err) {
// insert a document with id 'jack johns'
db.insert({ _id: 'jack johns', name: 'jack' }, function(err, body) {
if (err) {
console.log('insertion failed ', err.message);
return;
}
console.log(body);
// body will like following:
// { ok: true,
// id: 'jack johns',
// rev: '1-610953b93b8bf1bae12427e2de181307' }
});
});
});
//////////////////////////////
bot.onText(/^[\/!#]start$/, msg => {
const opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: [['Store username']],
resize_keyboard:true,
one_time_keyboard: true
})
};
bot.sendMessage(msg.chat.id, 'You Are Exist in DB', opts);
});
只是一般的邊緣情況下,你可能會想注意:有些人沒有用戶名,因爲它不是強制性的:) –
我知道親愛的,這是一個例子,由Myselfe解決 –
好聽,因爲你設法解決它自己記得標記爲答案。 –