@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
69 lines • 3.3 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _TeamsChatMessageListCommand_instances, _TeamsChatMessageListCommand_initOptions, _TeamsChatMessageListCommand_initValidators;
import { odata } from '../../../../utils/odata.js';
import { validation } from '../../../../utils/validation.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
class TeamsChatMessageListCommand extends GraphCommand {
get name() {
return commands.CHAT_MESSAGE_LIST;
}
get description() {
return 'Lists all messages from a chat';
}
defaultProperties() {
return ['id', 'shortBody'];
}
constructor() {
super();
_TeamsChatMessageListCommand_instances.add(this);
__classPrivateFieldGet(this, _TeamsChatMessageListCommand_instances, "m", _TeamsChatMessageListCommand_initOptions).call(this);
__classPrivateFieldGet(this, _TeamsChatMessageListCommand_instances, "m", _TeamsChatMessageListCommand_initValidators).call(this);
}
async commandAction(logger, args) {
const endpoint = `${this.resource}/v1.0/chats/${args.options.chatId}/messages`;
try {
const items = await odata.getAllItems(endpoint);
if (args.options.output !== 'json') {
items.forEach(i => {
// hoist the content to body for readability
i.body = i.body.content;
let shortBody;
const bodyToProcess = i.body;
if (bodyToProcess) {
let maxLength = 50;
let addedDots = '...';
if (bodyToProcess.length < maxLength) {
maxLength = bodyToProcess.length;
addedDots = '';
}
shortBody = bodyToProcess.replace(/\n/g, ' ').substring(0, maxLength) + addedDots;
}
i.shortBody = shortBody;
});
}
await logger.log(items);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
}
_TeamsChatMessageListCommand_instances = new WeakSet(), _TeamsChatMessageListCommand_initOptions = function _TeamsChatMessageListCommand_initOptions() {
this.options.unshift({
option: '-i, --chatId <chatId>'
});
}, _TeamsChatMessageListCommand_initValidators = function _TeamsChatMessageListCommand_initValidators() {
this.validators.push(async (args) => {
if (!validation.isValidTeamsChatId(args.options.chatId)) {
return `${args.options.chatId} is not a valid Teams chat ID`;
}
return true;
});
};
export default new TeamsChatMessageListCommand();
//# sourceMappingURL=chat-message-list.js.map