save with sendMsg working

This commit is contained in:
Helmut Merz 2023-03-10 15:02:46 +01:00
parent 59bb87d204
commit ff47987b41

View file

@ -64,13 +64,14 @@ function Data(name: string): object {
function save() {
const data = this.data
const conf = this.conf
let value = ''
for (const k of Object.keys(data)) {
value += `${k}: ${data[k]}, `
}
this.output += '\n' + value
console.log('save:', value)
// sendMsg(this.conf, [conf.domain, 'data', this.name, data.id], data)
sendMsg(conf, [conf.domain, 'data', this.name, data.id], data)
}
function poll() {
@ -87,11 +88,19 @@ function handle(msg) {
// basic functions - move to api.ts
async function sendMsg(conf: Config, basemsg: string[], data: any) {
const url = `${conf.apiurl}/${basemsg.join('/')}`
await send(url, conf, data)
}
async function send(url: string, conf: Config, data: any) {
data._interaction = conf.iid
const body = JSON.stringify(data)
const headers = {}
headers['X-Integrator-Session'] = conf.sid
return fetch(url, {
method: 'POST',
headers: headers,
body: body
})
}