Вот мой код.
Что я хочу сделать?
Хочу внутри одного объекта использовать его методы.
Не получается.
При вызове метода cancelAdd с использованием this, внутри метода start, node.js ругается, говорит, что метод cancelAdd - not function.
Помогите пожалуйста, мне не хватает знаний.
const config = require('../config/config');
const dictionaryOperations = (bot) =>{
return {
start: function (msg) {
let chatId = msg.chat.id;
let message = 'Welcome!\nThis bot can save words as dictionary';
let options = {
"reply_markup": {
"keyboard": [[config.replyKeyboard.addWordButton]],
"resize_keyboard": true,
}
};
bot.sendMessage(chatId, message, options);
this.cancelAdd(msg);
},
cancelAdd: function (msg) {
console.log( `cancel action`);
bot.send(msg.chat.id, 'Cancel action');
},
}
};
module.exports = dictionaryOperations;
А метод start я вызываю в файле app.js Ниже код
const express = require('express');
const config = require('./config/config');
const TelegramBot = require('node-telegram-bot-api');
const bodyParser = require('body-parser');
require('./config/configDB');
const app = express();
const bot = new TelegramBot (config.TOKEN);
bot.setWebHook(config.URL);
const dictionary = require('./controllers/dictionaryControllers')(bot);
app.listen(3000);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
app.post('/', (request, response)=>{
let req = request.body;
response.send().status(200);
bot.processUpdate(req);
});
const start = /\/start/;
bot.onText(start, dictionary.start);
msgвот тут(msg) => {и тутfunc1: function(msg) {иfunc2: function(msg) {- Это разные, ничем не связанные между собой переменные – Grundy Nov 08 '18 at 18:27startи как именно ты это делаешь – Grundy Nov 11 '18 at 17:20start? – Grundy Nov 11 '18 at 17:38И прощу прощения, я новичок здесь
– Aibek Sadraliev Nov 11 '18 at 17:43