-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
43 lines (37 loc) · 1.38 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { SlackMessage, UserMap, UserMapChatMeta } from './lib/types';
import fetchMessages from './lib/fetch-messages';
import fetchUsers from './lib/fetch-users';
import analyzer from './lib/analyzer';
import pipeline from './lib/pipeline';
import lowestScore from './lib/utils/lowest-score';
import findLowestScore from './lib/utils/find-lowest-score';
import ora = require('ora');
export const handler = async(): Promise<void> => {
const Spinner = ora();
try {
// fetch the messages
Spinner.text = 'Fetching messages';
Spinner.start();
const messages: SlackMessage[] = await fetchMessages();
Spinner.succeed('Fetched messages');
// fetch users
Spinner.text = 'Fetching users';
Spinner.start();
const users: UserMap = await fetchUsers( messages );
Spinner.succeed('Fetched users');
// calculate sentiment scores, message counts, and any other meta data for
// each user
Spinner.text = 'Calculating sentiment scores';
Spinner.start();
const meta: UserMapChatMeta = analyzer( users, messages );
Spinner.succeed('Calculated sentiment scores');
// save info about who has the lowest score
lowestScore.set( findLowestScore( meta ) );
// Run the Data Pipeline
await pipeline({ users, messages, meta });
} catch ( err ) {
Spinner.fail();
console.error( 'Failed with error: ', err );
process.exit( 1 );
}
};