Skip to content

Commit

Permalink
winston removed
Browse files Browse the repository at this point in the history
console.logs/debug... removed
Added tiledesk-logger in place of winston/console
  • Loading branch information
sponzillo committed Jun 16, 2021
1 parent 265a659 commit 2a523e1
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 378 deletions.
19 changes: 10 additions & 9 deletions chatdb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Andrea Sponziello - (c) Tiledesk.com
*/

const winston = require("../winston");
// const winston = require("../winston");
const logger = require('../tiledesk-logger').logger;

/**
* This is the class that manages DB persistence
Expand Down Expand Up @@ -38,11 +39,11 @@ class ChatDB {
}

saveOrUpdateMessage(message, callback) {
winston.debug("saving message...", message)
logger.debug("saving message...", message)
delete message['_id'] // if present (message is coming from a mongodb query?) it is illegal. It produces: MongoError: E11000 duplicate key error collection: tiledesk-dialogflow-proxy.messages index: _id_ dup key: { : "5ef72c2494e08ffec88a033a" }
this.db.collection(this.messages_collection).updateOne({timelineOf: message.timelineOf, message_id: message.message_id}, { $set: message }, { upsert: true }, function(err, doc) {
if (err) {
winston.error("db error...", err)
logger.error("db error...", err)
if (callback) {
callback(err, null)
}
Expand All @@ -56,25 +57,25 @@ class ChatDB {
}

saveOrUpdateConversation(conversation, callback) {
// winston.debug("saving conversation...", conversation)
// logger.debug("saving conversation...", conversation)
this.db.collection(this.conversations_collection).updateOne({timelineOf: conversation.timelineOf, conversWith: conversation.conversWith}, { $set: conversation}, { upsert: true }, function(err, doc) {
if (err) {
console.error("error saveOrUpdateConversation", err)
logger.error("error saveOrUpdateConversation", err)
if (callback) {
callback(err, null)
}
}
else {
if (callback) {
console.debug("Conversation saved.")
logger.debug("Conversation saved.")
callback(null, doc)
}
}
});
}

saveOrUpdateGroup(group, callback) {
winston.debug("saving group...", group)
logger.debug("saving group...", group)
this.db.collection(this.groups_collection).updateOne( { uid: group.uid }, { $set: group }, { upsert: true }, function(err, doc) {
if (callback) {
callback(err, null)
Expand Down Expand Up @@ -103,7 +104,7 @@ class ChatDB {
}

lastConversations(appid, userid, archived, callback) {
winston.debug("DB. app:", appid, "user:", userid, "archived:", archived)
logger.debug("DB. app:", appid, "user:", userid, "archived:", archived)
this.db.collection(this.conversations_collection).find( { timelineOf: userid, app_id: appid, archived: archived } ).limit(200).sort( { timestamp: -1 } ).toArray(function(err, docs) {
if (err) {
if (callback) {
Expand Down Expand Up @@ -134,7 +135,7 @@ class ChatDB {
}

lastMessages(appid, userid, convid, sort, limit, callback) {
winston.debug("DB. app:", appid, "user:", userid, "convid", convid)
logger.debug("DB. app:", appid, "user:", userid, "convid", convid)
this.db.collection(this.messages_collection).find( { timelineOf: userid, app_id: appid, conversWith: convid } ).limit(limit).sort( { timestamp: sort } ).toArray(function(err, docs) {
if (err) {
if (callback) {
Expand Down
13 changes: 7 additions & 6 deletions chatservermq.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

require('dotenv').config();

const winston = require("./winston");
// const winston = require("./winston");
const logger = require('./tiledesk-logger').logger;

var observer = require('./observer');
var startServer = observer.startServer;
Expand All @@ -20,24 +21,24 @@ if (webhook_enabled == undefined || webhook_enabled === "true" || webhook_enable
}else {
webhook_enabled = false;
}
winston.info("webhook_enabled: " + webhook_enabled);
logger.info("webhook_enabled: " + webhook_enabled);


var webhook_endpoint = process.env.WEBHOOK_ENDPOINT;
winston.info("webhook_endpoint: " + webhook_endpoint);
logger.info("webhook_endpoint: " + webhook_endpoint);


let webhook_events_array = null;
if (process.env.WEBHOOK_EVENTS) {
console.log(typeof process.env.WEBHOOK_EVENTS);
// logger.log(typeof process.env.WEBHOOK_EVENTS);
const webhook_events = process.env.WEBHOOK_EVENTS;
webhook_events_array = webhook_events.split(",");
}
winston.info("webhook_events_array: " , webhook_events_array);
logger.info("webhook_events_array: " , webhook_events_array);



winston.info("Starting observer")
logger.info("Starting observer")
async function start() {

observer.setWebHookEnabled(webhook_enabled);
Expand Down
Loading

0 comments on commit 2a523e1

Please sign in to comment.