2020-11-04 22:59:32 +01:00
|
|
|
import { TapiContact } from './tapi-contact'
|
|
|
|
import { axios, extractNumber } from './utils'
|
|
|
|
|
|
|
|
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)
|
|
|
|
var response = await axios.get<TapiContact>('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 = response.data
|
|
|
|
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
|
|
|
|
GM.notification(notification)
|
|
|
|
}
|
|
|
|
}
|