Skip to content

Commit d5d47e7

Browse files
committed
send slack message
1 parent e1a6813 commit d5d47e7

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

AutomaticClockOuts/clock_out.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const MsalClient = require('./msal_client')
66

77
const doClockOut = async (context, timer) => {
88
context.log(`I am going to check how many entries were not clocked out ${new Date()}`);
9-
const {endpoint, key, databaseId, containerId, azureEndpoint} = config;
9+
const {endpoint, key, databaseId, containerId, slackWebHook} = config;
1010
const client = new CosmosClient({endpoint, key});
1111
const database = client.database(databaseId);
1212
const container = database.container(containerId);
@@ -33,7 +33,7 @@ const doClockOut = async (context, timer) => {
3333
}
3434
}));
3535
if(totalClockOutsExecuted > 0){
36-
axios.post(process.env["SLACK_WEBHOOK"],
36+
axios.post(slackWebHook,
3737
{
3838
"text": `Hey guys, I did a clock out for you. \nVisit https://timetracker.ioet.com/ and set the right end time for your entries :pls: \n- ${usersWithClockOut.join('\n- ')}`
3939
}

AutomaticClockOuts/config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const config = {
2-
endpoint: "https://time-tracker-db.documents.azure.com:443/",
3-
key: process.env["COSMOS_DB_KEY"],
2+
endpoint: "xxx",
3+
key: "xxx",
44
databaseId: "time-tracker-db",
55
containerId: "time_entry",
66
partitionKey: { kind: "Hash", paths: ["/category"] },
7-
client_id: process.env["MS_CLIENT_ID"],
8-
authority: process.env["MS_AUTHORITY"],
9-
clientSecret: process.env["MS_CLIENT_SECRET"]
7+
clientId: "xxx",
8+
authority: "xxx",
9+
clientSecret: "xxx",
10+
slackWebHook: "xxx"
1011
};
1112

1213
module.exports = config;

AutomaticClockOuts/msal_client.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
const axios = require("axios")
22
const msal = require('@azure/msal-node');
3+
const config = require("./config");
34

45
const findUsersInMS = async() => {
6+
const {clientId, authority, clientSecret} = config;
57
const endpoint = 'https://graph.windows.net/ioetec.onmicrosoft.com'
6-
const config = {
8+
const configuration = {
79
auth: {
8-
clientId: process.env["MS_CLIENT_ID"],
9-
authority: process.env["MS_AUTHORITY"],
10-
clientSecret: process.env["MS_CLIENT_SECRET"]
10+
clientId: clientId,
11+
authority: authority,
12+
clientSecret: clientSecret
1113
}
1214
};
1315

14-
console.log('---------------------------------------------')
15-
console.log(JSON.stringify(config))
16-
17-
const cca = new msal.ConfidentialClientApplication(config);
16+
const cca = new msal.ConfidentialClientApplication(configuration);
1817
const clientCredentialRequest = {
1918
scopes: ['https://graph.windows.net/.default'],
2019
};

AutomaticClockOuts/test/msal_client.spec.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ const test = require('ava');
22
const MsalClient = require('../msal_client')
33

44
test('Response contains ioet.com since users has it as part their emails', async t => {
5-
const users =
6-
// {
7-
// data: {
8-
// value: '[email protected]'
9-
// }
10-
// }
11-
await MsalClient.findUsersInMS()
12-
13-
console.log('---------------------------value')
14-
console.log(users.data.value)
5+
const users = await MsalClient.findUsersInMS()
156

167
t.truthy(JSON.stringify(users.data.value).includes("ioet.com"))
178
})

0 commit comments

Comments
 (0)