Switch to Typescript and webpack
This commit is contained in:
31
src/js/call-notification.ts
Normal file
31
src/js/call-notification.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { TapiContact } from './tapi-contact'
|
||||
import { axios, extractNumber } from './utils'
|
||||
|
||||
export class CallNotification {
|
||||
public async showCallNotification (element: HTMLElement) {
|
||||
var number = element.dataset.id
|
||||
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) {
|
||||
notification.text = callerId.tD_NAME + '\r\n' + number
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
GM.notification(notification)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user