You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* As noted in #193, pagination is not yet dealt with, so only the most recent 20 conversations are included.
*/
importclifrom'@battis/qui-cli';import{parseasparseCSV,stringify}from'csv/sync';import{api,PuppeteerSession}from'datadirect-puppeteer';importmomentfrom'moment';importfsfrom'node:fs/promises';importpathfrom'node:path';import*ascommonfrom'../common.js';import*asArgsfrom'./Inbox/Args.js';export{Args};exporttypeOptions=Args.Parsed;constAnalyticsColumns={Conversations: 'Conversations',MostRecentConversation: 'Most Recent Conversation',Sent: 'Sent',MostRecentSent: 'Most Recent Sent'};exportasyncfunctionanalytics(url?: URL|string,pathToUserListCsv?: string,options?: Args.Parsed): Promise<void>;exportasyncfunctionanalytics(url?: URL|string,options?: Args.Parsed): Promise<void>;exportasyncfunctionanalytics(url?: URL|string,pathToUserListCsvOrOptions?: string|Args.Parsed,options?: Args.Parsed): Promise<void>{if(!url){thrownewError(`Instance URL must be defined`);}letpathToUserList: string|undefined=undefined;if(typeofpathToUserListCsvOrOptions==='string'){pathToUserList=pathToUserListCsvOrOptions;}elseif(!pathToUserListCsvOrOptions&&options){pathToUserList=undefined;}elseif(!options){options=pathToUserListCsvOrOptions;}options=common.Args.hydrate<Args.Parsed>(options,Args.defaults);const{
puppeteerOptions,
logRequests,
vals,
column,
searchIn,
outputOptions,
quit,
..._options}=options;let{ outputPath }=outputOptions;letcolumns=[column];letdata: Record<string,string|number>[]=[];if(pathToUserList){data=awaitparseCSV(awaitfs.readFile(path.resolve(process.cwd(),pathToUserList)),{bom: true,columns: (row: string[])=>{if(!row.includes(column)){thrownewError(`Column ${cli.colors.quotedValue(`"${column}`)} not found in CSV data: ${row.map((col)=>cli.colors.quotedValue(col)).join(', ')}`);}columns=row;returnrow;}});data.push(...vals.map((val)=>({[column]: val})));}else{data=vals.map((val)=>({[column]: val}));}if(data.length===0){thrownewError(`Inbox users must be passed as either a path to a CSV file or a list of ${cli.colors.value('val')}`);}constroot=awaitPuppeteerSession.Authenticated.getInstance(url,{
...puppeteerOptions,
..._options});constprogress=newcommon.ProgressBar({max: data.length});outputPath=awaitcommon.Output.avoidOverwrite(path.resolve(process.cwd(),common.Output.filePathFromOutputPath(outputPath,path.basename(Args.defaults.outputOptions.outputPath))));letwriting: Promise<void>|undefined=undefined;columns.push(...Object.values(AnalyticsColumns));for(constrowofdata){constval=''+row[column];try{constsession=awaitPuppeteerSession.Impersonation.getInstance(root,{
searchIn,
val,
...puppeteerOptions,
..._options});progress.caption(session.userInfo?.UserNameFormatted||val);/* * FIXME Inbox pagination * As noted in #193, pagination is not yet dealt with, so only the most recent 20 conversations are included. */constconversations=awaitapi.message.inbox({
session,payload: {format: 'json',pageNumber: 1,toDate: moment().format('MM/DD/YYYY')},
logRequests
});row[AnalyticsColumns.Conversations]=conversations.length;constrecent=conversations.reduce((recent: Date|undefined,c)=>{constreceived=c.Messages.map((m)=>newDate(m.SendDate)).reduce((max: Date|undefined,m)=>(max&&max>m ? max : m),undefined);if(recent&&received&&recent>received){returnrecent;}returnreceived;},undefined);if(recent){row[AnalyticsColumns.MostRecentConversation]=recent.toLocaleString();}row[AnalyticsColumns.Sent]=conversations.reduce((sum,c)=>sum+c.Messages.filter((m)=>m.FromUser.UserId===session.userInfo?.UserId).length,0);constrecentSent=conversations.reduce((recent: Date|undefined,c)=>{constsent=c.Messages.filter((m)=>m.FromUser.UserId===session.userInfo?.UserId).map((m)=>newDate(m.SendDate)).reduce((max: Date|undefined,m)=>(max&&max>m ? max : m),undefined);if(recent&&sent&&recent>sent){returnrecent;}returnsent;},undefined);if(recentSent){row[AnalyticsColumns.MostRecentSent]=recentSent.toLocaleString();}awaitsession.close();}catch(error){cli.log.error(`Error impersonating ${val}: ${cli.colors.error(error)}`);}awaitwriting;writing=fs.writeFile(outputPath,stringify(data,{header: true, columns }));progress.increment();}awaitwriting;if(quit){awaitroot.close();}progress.stop();cli.log.info(`Analytics written to ${cli.colors.url(outputPath)}`);}
The text was updated successfully, but these errors were encountered:
As noted in #193, pagination is not yet dealt with, so only the most recent 20 conversations are included.
myschoolapp-reporting/packages/msar/src/workflows/Inbox.ts
Lines 119 to 121 in 7159912
The text was updated successfully, but these errors were encountered: