javascript - Trying to post an image to a bot, however it gets posted multiple times. Unable to figure out where the loop is occuring -
i have created bot posts image whenever type after mentioning bot's name. however, bot should post image once keeps posting multiple time. appreciate in figuring out solution flaw
'use strict'; var util = require('util'); var path = require('path'); var fs = require('fs'); var bot = require('slackbots'); var http = require('http'); var sethubot = function constructor(settings) { this.settings = settings; this.settings.name = this.settings.name || 'mufc'; this.user = null; }; util.inherits(sethubot, bot); sethubot.prototype.run = function() { sethubot.super_.call(this, this.settings); this.on('start', this._onstart); this.on('message', this._onmessage); }; sethubot.prototype._onstart = function() { this._loadbotuser(); }; sethubot.prototype._onmessage = function(message) { if (this._ischatmessage(message) && !this._isfromsethubot(message)) { this._smartresponse(message); } }; sethubot.prototype._smartresponse = function(originalmessage) { var self = this; var channel = self._getchannelbyid(originalmessage.channel); var urltoquery = ''; var firstname = ''; var = 'http://i.telegraph.co.uk/multimedia/archive/03481/david_beckham_3481418k.jpg'; self.postmessagetochannel(channel.name, a, { as_user: true, attachments: [{ "fallback": "required plain-text summary of theattachment.", "color": "#36a64f", "image_url": // "ts": 1 }] }); }; sethubot.prototype._loadbotuser = function() { var self = this; this.user = this.users.filter(function(user) { return user.name === self.name; })[0]; }; sethubot.prototype._ischatmessage = function(message) { return message.type === 'message' && boolean(message.text); }; sethubot.prototype._ischannelconversation = function(message) { return typeof message.channel === 'string' && message.channel[0] === 'c'; }; sethubot.prototype._isfromsethubot = function(message) { return message.user === this.user.id; }; sethubot.prototype._getchannelbyid = function(channelid) { return this.channels.filter(function(item) { return item.id === channelid; })[0]; }; module.exports = sethubot;
Comments
Post a Comment