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