Update format send zulip
This commit is contained in:
parent
4e5099aea8
commit
2bc1338316
|
|
@ -42,6 +42,7 @@ interface LineConfig {
|
||||||
detectAI?: {
|
detectAI?: {
|
||||||
status: string[]
|
status: string[]
|
||||||
issue: string[]
|
issue: string[]
|
||||||
|
summary: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -86,6 +87,7 @@ interface DataDPELP {
|
||||||
mac: string
|
mac: string
|
||||||
license: any
|
license: any
|
||||||
issues: string[]
|
issues: string[]
|
||||||
|
summary: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LineConnection {
|
export default class LineConnection {
|
||||||
|
|
@ -123,6 +125,7 @@ export default class LineConnection {
|
||||||
mac: '',
|
mac: '',
|
||||||
license: [],
|
license: [],
|
||||||
issues: ['No data'],
|
issues: ['No data'],
|
||||||
|
summary: '',
|
||||||
}
|
}
|
||||||
this.retryConnect = 0
|
this.retryConnect = 0
|
||||||
this.handleClearLine = handleClearLine
|
this.handleClearLine = handleClearLine
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import zulip from 'zulip-js'
|
||||||
type DetectAI = {
|
type DetectAI = {
|
||||||
status: string[]
|
status: string[]
|
||||||
issue: string[]
|
issue: string[]
|
||||||
|
summary: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type InputData = {
|
type InputData = {
|
||||||
|
|
@ -160,6 +161,7 @@ export function mapToLineFormat(input: InputData) {
|
||||||
mac: '',
|
mac: '',
|
||||||
license: [],
|
license: [],
|
||||||
issues: ['No data'],
|
issues: ['No data'],
|
||||||
|
summary: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,6 +201,8 @@ export function mapToLineFormat(input: InputData) {
|
||||||
: input.latestScenario?.detectAI?.issue
|
: input.latestScenario?.detectAI?.issue
|
||||||
? [input.latestScenario.detectAI.issue]
|
? [input.latestScenario.detectAI.issue]
|
||||||
: []
|
: []
|
||||||
|
// Issues
|
||||||
|
const summary = input.latestScenario?.detectAI?.summary || ''
|
||||||
|
|
||||||
return {
|
return {
|
||||||
line,
|
line,
|
||||||
|
|
@ -209,6 +213,7 @@ export function mapToLineFormat(input: InputData) {
|
||||||
mac,
|
mac,
|
||||||
license,
|
license,
|
||||||
issues,
|
issues,
|
||||||
|
summary,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -411,6 +411,11 @@ export class WebSocketIo {
|
||||||
try {
|
try {
|
||||||
const { ip, station } = data
|
const { ip, station } = data
|
||||||
const element = this.switchControl.get(ip)
|
const element = this.switchControl.get(ip)
|
||||||
|
|
||||||
|
// Connect station if not connected
|
||||||
|
const stationData = await Station.findBy('id', station.id)
|
||||||
|
if (stationData) await this.connectStation(stationData)
|
||||||
|
|
||||||
if (element && element.status === 'CONNECTED') {
|
if (element && element.status === 'CONNECTED') {
|
||||||
socket.emit('switch_output', {
|
socket.emit('switch_output', {
|
||||||
stationId: station.id,
|
stationId: station.id,
|
||||||
|
|
@ -574,14 +579,14 @@ export class WebSocketIo {
|
||||||
await sendMessageToMail(
|
await sendMessageToMail(
|
||||||
'andrew.ng@apactech.io',
|
'andrew.ng@apactech.io',
|
||||||
`[DPELP] - ${stationName} - ${dataFormat}`,
|
`[DPELP] - ${stationName} - ${dataFormat}`,
|
||||||
tableHTML,
|
tableHTML
|
||||||
['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
|
// ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
|
||||||
)
|
)
|
||||||
await sendMessageToZulip(
|
await sendMessageToZulip(
|
||||||
'stream',
|
'stream',
|
||||||
'ATC_Report',
|
'ATC_Report',
|
||||||
station.name,
|
station.name,
|
||||||
`\n\n---\n[DPELP] - ${stationName} - ${dataFormat}\n` + zulipMess
|
`\n\n---\n**[DPELP] - ${stationName} - ${dataFormat}**\n\n` + zulipMess
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|
@ -1042,6 +1047,7 @@ export class WebSocketIo {
|
||||||
<th>MAC</th>
|
<th>MAC</th>
|
||||||
<th style="width:270px; text-align:center;">IOS</th>
|
<th style="width:270px; text-align:center;">IOS</th>
|
||||||
<th style="width:200px; word-wrap: break-word; white-space: normal;">License</th>
|
<th style="width:200px; word-wrap: break-word; white-space: normal;">License</th>
|
||||||
|
<th>Summary</th>
|
||||||
<th>Issues</th>
|
<th>Issues</th>
|
||||||
</tr>
|
</tr>
|
||||||
`
|
`
|
||||||
|
|
@ -1075,6 +1081,7 @@ export class WebSocketIo {
|
||||||
<td>${item.mac || ''}</td>
|
<td>${item.mac || ''}</td>
|
||||||
<td style="width:270px">${item.ios || ''}</td>
|
<td style="width:270px">${item.ios || ''}</td>
|
||||||
<td style="width:200px;">${licenseHTML}</td>
|
<td style="width:200px;">${licenseHTML}</td>
|
||||||
|
<td style="width:200px; text-wrap: wrap;">${item.summary || ''}</td>
|
||||||
<td>${item.issues?.length ? `- ` + item.issues.join(`<br>- `) : ''}</td>
|
<td>${item.issues?.length ? `- ` + item.issues.join(`<br>- `) : ''}</td>
|
||||||
</tr>
|
</tr>
|
||||||
`
|
`
|
||||||
|
|
@ -1091,32 +1098,37 @@ export class WebSocketIo {
|
||||||
* @returns {string} The Markdown table string.
|
* @returns {string} The Markdown table string.
|
||||||
*/
|
*/
|
||||||
generateZulipMessage(results: any[]) {
|
generateZulipMessage(results: any[]) {
|
||||||
let msg = ''
|
let msg = ``
|
||||||
|
msg += `| Line | PID | SN | MAC | IOS | License | Summary | Issues |\n`
|
||||||
|
msg += `| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |\n`
|
||||||
|
|
||||||
for (const item of results) {
|
for (const item of results) {
|
||||||
if (!item) continue
|
if (!item) continue
|
||||||
|
|
||||||
|
// Format licenses
|
||||||
const licenses = Array.isArray(item.license)
|
const licenses = Array.isArray(item.license)
|
||||||
? [...new Set(item.license)]
|
? [...new Set(item.license)]
|
||||||
: item.license
|
: item.license
|
||||||
? [item.license]
|
? [item.license]
|
||||||
: []
|
: []
|
||||||
|
|
||||||
const issues = item.issues || []
|
const licenseMd = licenses.length ? licenses.map((l) => `• ${l}`).join(' --') : ''
|
||||||
|
|
||||||
msg += `**Line ${item.line || '?'} — ${item.pid || ''}${item.vid ? ` (${item.vid})` : ''} `
|
// Format issues
|
||||||
msg += `**SN:** **${item.sn || ''}** \n`
|
const issuesMd = item.issues?.length
|
||||||
msg += '```' + `\n`
|
? item.issues.map((i: string) => `• ${i}`).join(' --')
|
||||||
|
: ''
|
||||||
|
|
||||||
msg += `MAC: ${item.mac || ''} \n`
|
msg +=
|
||||||
msg += `IOS: ${item.ios || ''} \n`
|
`| ${item.line || ''}` +
|
||||||
|
` | ${item.pid || ''} ${item.vid ? ` (${item.vid})` : ''}` +
|
||||||
msg += `License: ${licenses.join(', ') || ''} \n`
|
` | ${item.sn || ''}` +
|
||||||
msg += `Issues: \n`
|
` | ${item.mac || ''}` +
|
||||||
if (issues.length) {
|
` | ${item.ios || ''}` +
|
||||||
for (const i of issues) msg += `• ${i} \n`
|
` | ${licenseMd}` +
|
||||||
} else msg += `• No issues detected.\n`
|
` | ${item.summary || ''}` +
|
||||||
msg += '```\n'
|
` | ${issuesMd}` +
|
||||||
|
` |\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue