skip to Main Content

so im stuck at this error. Im making a telegram bot with the telegram bot api and now im trying to set up a firebae DB to save the score of a group member – so the score is not resetted after restarting the bot. can someone tell me what the problem is? i read a lot of other issues here with similiar problems, but none of these answers fixed my problem.

bot.js

var TelegramBot = require('node-telegram-bot-api');
var firebase = require('firebase');

var token = 'mytoken';
// Setup polling way
var bot = new TelegramBot(token, {polling: true});

var app = firebase.intializeApp({
  serviceAccount: "C:/Mayer/scorebot/telegramscorebot.json",
  databaseURL: "https://blazing-heat-2008.firebaseio.com/"
});


/* function Person(name, score) {
this.name = name;
this.score = score;
}

var member = new Array();
member[0] = new Person("name1", 0);
member[1] = new Person("name2", 0);
member[2] = new Person("name3", 0);
member[3] = new Person("name4", 0);
member[4] = new Person("name5", 0); */

bot.onText(//echo (.+)/, function (msg, match) {
  var fromId = msg.from.id;
  if (match[1] == 'test') {
  var resp = match[1];
  bot.sendMessage(fromId, resp); }
  else {
  bot.sendMessage(fromId, 'error!!');}
});

bot.onText(//vote (.+)/, function (msg, match) {
  var fromId = msg.from.id;

for (var i = 0; i <= 4; i++) {
    if(member[i].name == match[1]){
        member[i].score += 1;
        bot.sendMessage(fromId, member[i].name + ' hat einen Score von ' +         member[i].score);}
}
});

package.json

   {
   "name": "scorebot",
   "version": "1.0.0",
   "description": "",
   "main": "bot.js",
   "scripts": {
     "test": "echo "Error: no test specified" && exit 1",
    "start": "node bot.js"
   },
   "author": "me",
   "license": "ISC",
   "dependencies": {
     "bower": "1.7.9",
    "firebase": "3.0.2"
   }
 }

Error message

 bot.js:8 var app = firebase.intializeApp({
                    ^

  TypeError: firebase.intializeApp is not a function
      at Object.<anonymous> (C:Mayerscorebotbot.js:8:20)
      at Module._compile (module.js:413:34)
      at Object.Module._extensions..js (module.js:422:10)
      at Module.load (module.js:357:32)
      at Function.Module._load (module.js:314:12)
      at Function.Module.runMain (module.js:447:10)
      at startup (node.js:141:18)
      at node.js:933:3

4

Answers


  1. See the docs here: https://www.npmjs.com/package/firebase

    You need to require the ‘app’ when in the browser context like so…

    const firebase = require('firebase/app');
    
    const app = firebase.initializeApp({ ... });
    
    Login or Signup to reply.
  2. Oops! You misspelled “initialize”. But pho3nixf1re said it best.

    Login or Signup to reply.
  3. You have a typo in firebase.intializeApp.

    It should be initializeApp.

    var app = firebase.initializeApp({...});
    
    Login or Signup to reply.
  4. For those reading this later, I’m using ES Modules from Node v14 and solved it with:

    import firebase from '@firebase/app';
    import "@firebase/database";
    
    firebase.default.initializeApp(firebaseConfig);
    let db = firebase.default.database();
    

    ☕️

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search