node-groupme
Version:
The only GroupMe API library that isn't a million years old.
35 lines • 1.26 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
class Chat extends __1.Channel {
constructor(client, user, data) {
super(client, __1.Channel.dataFromChat(data));
this.type = __1.ChannelType.Chat;
this.conversationID = data.last_message.conversation_id;
this.recipient = user;
this.messages = new __1.ChatMessageManager(client, this);
}
_patch(data) {
this.recipient._patch({
name: data.other_user?.name,
avatar_url: data.other_user?.avatar_url,
});
__1.Channel._patch(this, __1.Channel.dataFromChat(data)); // this is dangerous
return this;
}
async send(text) {
const body = {
direct_message: {
text,
attachments: [],
source_guid: this.client.rest.guid(),
recipient_id: this.recipient.id,
},
};
const response = await this.client.rest.api('POST', 'direct_messages', { body });
const message = new __1.ChatMessage(this.client, this, response.direct_message);
return this.messages._upsert(message);
}
}
exports.default = Chat;
//# sourceMappingURL=Chat.js.map