3cx_tapi/src/call-notification.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-10-14 11:49:10 +02:00
import GM_fetch from './gm-fetch'
2020-11-04 22:59:32 +01:00
import { TapiContact } from './tapi-contact'
2024-10-14 10:59:19 +02:00
import { extractNumber } from './utils'
2020-11-04 22:59:32 +01:00
export class CallNotification {
public async showCallNotification (element: HTMLElement) {
2021-11-30 14:20:13 +01:00
var number = element.querySelector('.callNumber').textContent
2020-11-04 22:59:32 +01:00
console.log('TAPI call notification', number)
number = extractNumber(number)
if (!number) {
console.log('TAPI callerid no number found')
return
}
console.log('TAPI searching callerid for', number)
2024-10-14 10:59:19 +02:00
var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number))
2020-11-04 22:59:32 +01:00
console.log('TAPI callerid response', response)
var notification = {
text: number
}
if (response.status === 200) {
2024-10-14 10:59:19 +02:00
var callerId = await response.json() as TapiContact
2020-11-04 22:59:32 +01:00
if (callerId) {
2020-11-09 08:53:39 +01:00
notification.text = callerId.tD_NAME + '\r\n' + number + ' (' + callerId.tD_MEDIUM + ')'
2020-11-04 22:59:32 +01:00
}
}
// eslint-disable-next-line no-undef
2024-10-14 10:59:19 +02:00
GM.notification(notification.text, 'TAPI Anruf')
2020-11-04 22:59:32 +01:00
}
}