save with sendMsg working
This commit is contained in:
parent
59bb87d204
commit
ff47987b41
1 changed files with 10 additions and 1 deletions
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue