33 *
44 * run with:
55 APP_INSIGHTS_ID="X" APP_INSIGHTS_API_KEY="Y" node packages/typescriptlang-org/scripts/pingTeamsWithAppInsightData.js
6+
7+ if process.env.STATS_WEBHOOK_INCOMING_URL is set, then the message will go into teams
68 */
79
810const nodeFetch = require ( "node-fetch" ) . default
911const querystring = require ( "querystring" )
1012
1113const go = async ( ) => {
1214 const dl = await getDetailsForDownloadIntention ( )
13- console . log ( { dl } )
14- return
1515
1616 // Sessions
1717 const all = await getCountForSessions ( )
@@ -30,7 +30,7 @@ const go = async () => {
3030 // Users
3131 const allUsers = await getCountForQuery ( getUsersAllPrefixed ( ) )
3232
33- // console.log({ allUsers, all, index, playground, handbook })
33+ // https://adaptivecards.io/designer
3434
3535 const headline = {
3636 type : "FactSet" ,
@@ -44,12 +44,16 @@ const go = async () => {
4444 value : comma ( allUsers ) ,
4545 } ,
4646 {
47- title : "Homepage" ,
47+ title : "Homepage Sessions " ,
4848 value : comma ( index ) ,
4949 } ,
5050 ] ,
5151 }
5252
53+ const homepageSection = makeColumn ( "Download" , {
54+ All : comma ( dl ) ,
55+ } )
56+
5357 const playgroundSection = makeColumn ( "Playground Usage" , {
5458 All : comma ( playground ) ,
5559 } )
@@ -71,12 +75,39 @@ const go = async () => {
7175 headline ,
7276 {
7377 type : "ColumnSet" ,
74- columns : [ playgroundSection , handbookSection , jsInTSSection ] ,
78+ columns : [
79+ homepageSection ,
80+ playgroundSection ,
81+ handbookSection ,
82+ jsInTSSection ,
83+ ] ,
7584 } ,
7685 ] ,
7786 }
7887
79- console . log ( JSON . stringify ( card ) )
88+ if ( ! process . env . STATS_WEBHOOK_INCOMING_URL ) {
89+ console . log ( JSON . stringify ( card , null , " " ) )
90+ } else {
91+ // https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook
92+
93+ const outer = {
94+ type : "message" ,
95+ attachments : [
96+ {
97+ contentType : "application/vnd.microsoft.card.adaptive" ,
98+ contentUrl : null ,
99+ content : card ,
100+ } ,
101+ ] ,
102+ }
103+
104+ const r = await nodeFetch ( process . env . STATS_WEBHOOK_INCOMING_URL , {
105+ method : "post" ,
106+ body : JSON . stringify ( outer ) ,
107+ headers : { "Content-Type" : "application/json" } ,
108+ } )
109+ console . log ( r )
110+ }
80111}
81112
82113go ( )
@@ -182,8 +213,7 @@ async function getDetailsForDownloadIntention() {
182213 | make-series Sessions = dcount(session_Id) default = 0 on timestamp from ago(7d) to now() step iff(true, 7d, 7d)`
183214
184215 const response = await makeQuery ( query )
185- console . log ( response . tables [ 0 ] . rows )
186- return { }
216+ return JSON . parse ( response . tables [ 0 ] . rows [ 0 ] [ 0 ] ) [ 0 ]
187217}
188218
189219function comma ( x ) {
0 commit comments