Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (msg.data.channel_type === 'D') {
if (!new RegExp(`^@?${this.robot.name}`, 'i').test(text)) { // Direct message
text = `${this.robot.name} ${text}`;
}
if (!user.mm) { user.mm = {}; }
user.mm.dm_channel_id = mmPost.channel_id;
}
this.robot.logger.debug(`Text: ${text}`);
if (mmPost.file_ids) {
this.receive(new AttachmentMessage(user, text, mmPost.file_ids, mmPost.id));
// If there are interesting props, then include them for bot handlers.
} else if ( mmPost.props ? mmPost.props.attachments : undefined ) {
this.receive(new TextAndPropsMessage(user, text, mmPost.props, mmPost.id));
} else {
this.receive(new TextMessage(user, text, mmPost.id));
}
this.robot.logger.debug("Message sent to hubot brain.");
return true;
}
this.receive(new TextMessage(user, text, message.message_id))
// Callback query
} else if (message.data) {
text = this.cleanMessageText(message.data, message.message.chat.id)
this.robot.logger.debug(`Received callback query: ${message.from.username} said '${text}'`)
user = this.createUser(message.from, message.message.chat)
this.api.invoke('answerCallbackQuery', { callback_query_id: message.id }, function (err, result) {
if (err) {
this.robot.logger.error(err)
}
})
this.receive(new TextMessage(user, text, message.message.message_id))
// Join event
} else if (message.new_chat_member) {
user = this.createUser(message.new_chat_member, message.chat)
this.robot.logger.info(`User ${user.id} joined chat ${message.chat.id}`)
this.receive(new EnterMessage(user, null, message.message_id))
// Exit event
} else if (message.left_chat_member) {
user = this.createUser(message.left_chat_member, message.chat)
this.robot.logger.info(`User ${user.id} left chat ${message.chat.id}`)
this.receive(new LeaveMessage(user, null, message.message_id))
// Chat topic event
} else if (message.new_chat_title) {
user = this.createUser(message.from, message.chat)
if (message.chat.type === 'group') groupsManager.update(message.chat.id, { name: message.chat.title })
if (this.robot.brain.get(`handled${message.message_id}`) === true) {
this.robot.logger.warning(`Message ${message.message_id} already handled.`)
return
}
this.robot.brain.set(`handled${message.message_id}`, true)
// Text event
if (message.text) {
text = this.cleanMessageText(message.text, message.chat.id)
this.robot.logger.info(`Received message: ${message.from.first_name} ${message.from.last_name} said '${text}'`)
user = this.createUser(message.from, message.chat)
this.receive(new TextMessage(user, text, message.message_id))
// Callback query
} else if (message.data) {
text = this.cleanMessageText(message.data, message.message.chat.id)
this.robot.logger.debug(`Received callback query: ${message.from.username} said '${text}'`)
user = this.createUser(message.from, message.message.chat)
this.api.invoke('answerCallbackQuery', { callback_query_id: message.id }, function (err, result) {
if (err) {
this.robot.logger.error(err)
}
})
this.receive(new TextMessage(user, text, message.message.message_id))
return new Promise(resolve => {
let textMessage = null;
if ((typeof message === 'object') && message) {
textMessage = message;
} else {
userParams.room = this.name;
const user = new Hubot.User(userName, userParams);
textMessage = new Hubot.TextMessage(user, message);
}
this.messages.push([userName, textMessage.text]);
this.robot.receive(textMessage, resolve);
});
}