3cx_tapi/src/call-notification.ts
Daniel Triendl 748a8740eb Revert "gm-fetch für Firefox gefixt"
This reverts commit 20e011bb5507948894f9500355b457aa349556e9.
2024-10-15 16:45:21 +02:00

33 lines
1.0 KiB
TypeScript

import GM_fetch from '@trim21/gm-fetch'
import { TapiContact } from './tapi-contact'
import { extractNumber } from './utils'
export class CallNotification {
public async showCallNotification (element: HTMLElement) {
var number = element.querySelector('.callNumber').textContent
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)
var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number))
console.log('TAPI callerid response', response)
var notification = {
text: number
}
if (response.status === 200) {
var callerId = await response.json() as TapiContact
if (callerId) {
notification.text = callerId.tD_NAME + '\r\n' + number + ' (' + callerId.tD_MEDIUM + ')'
}
}
// eslint-disable-next-line no-undef
GM.notification(notification.text, 'TAPI Anruf')
}
}