salix/back/methods/chat/send.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-01-20 06:33:24 +00:00
module.exports = Self => {
Self.remoteMethodCtx('send', {
description: 'Send a RocketChat message',
accessType: 'WRITE',
accepts: [{
arg: 'to',
2021-03-15 11:26:11 +00:00
type: 'string',
2020-01-20 06:33:24 +00:00
required: true,
2020-01-23 12:31:07 +00:00
description: 'User (@) or channel (#) to send the message'
2020-01-20 06:33:24 +00:00
}, {
arg: 'message',
2021-03-15 11:26:11 +00:00
type: 'string',
2020-01-20 06:33:24 +00:00
required: true,
description: 'The message'
}],
returns: {
2021-03-15 11:26:11 +00:00
type: 'object',
2020-01-20 06:33:24 +00:00
root: true
},
http: {
path: `/send`,
verb: 'POST'
}
});
Self.send = async(ctx, to, message) => {
const models = Self.app.models;
const accessToken = ctx.req.accessToken;
const sender = await models.Account.findById(accessToken.userId);
const recipient = to.replace('@', '');
if (sender.name != recipient) {
await models.Chat.create({
senderFk: sender.id,
recipient: to,
dated: new Date(),
checkUserStatus: 0,
message: message,
status: 0,
attempts: 0
});
2022-04-07 06:51:07 +00:00
2022-04-07 09:54:08 +00:00
return true;
}
2020-01-20 06:33:24 +00:00
2022-06-03 11:36:21 +00:00
return false;
};
2020-01-20 06:33:24 +00:00
};