|
1 | 1 | // https://developer.amazon.com/docs/alexa-voice-service/system.html |
| 2 | +import * as http2 from "http2"; |
2 | 3 |
|
3 | | -export default class System {} |
| 4 | +import {API_VERSION, HTTP2_BOUNDARY} from "./constants/general"; |
| 5 | +import Http2Utility from "./http2-utility"; |
| 6 | + |
| 7 | +export default class System { |
| 8 | + private readonly http2Utility: Http2Utility; |
| 9 | + |
| 10 | + constructor(private readonly client: http2.ClientHttp2Session) { |
| 11 | + this.http2Utility = new Http2Utility(); |
| 12 | + } |
| 13 | + |
| 14 | + public synchronizeState(accessToken: string, context: AVS.Context): void { |
| 15 | + const req = this.client.request({ |
| 16 | + ":method": "POST", |
| 17 | + ":path": `/${API_VERSION}/events`, |
| 18 | + authorization: `Bearer ${accessToken}`, |
| 19 | + "content-type": `multipart/form-data; boundary=${HTTP2_BOUNDARY}`, |
| 20 | + }); |
| 21 | + |
| 22 | + console.log("okie"); |
| 23 | + |
| 24 | + // req.on("response", (headers, flags) => { |
| 25 | + // for (const name in headers) { |
| 26 | + // console.log(`${name}: ${headers[name]}`); |
| 27 | + // } |
| 28 | + // }); |
| 29 | + |
| 30 | + const f = this.http2Utility.createMetadata({ |
| 31 | + context: context, |
| 32 | + event: { |
| 33 | + header: { |
| 34 | + namespace: "System", |
| 35 | + name: "SynchronizeState", |
| 36 | + messageId: "test", |
| 37 | + }, |
| 38 | + payload: {}, |
| 39 | + }, |
| 40 | + }); |
| 41 | + |
| 42 | + req.write(f, () => { |
| 43 | + console.log("dun knoe"); |
| 44 | + console.log(); |
| 45 | + }); |
| 46 | + |
| 47 | + req.setEncoding("utf8"); |
| 48 | + let data = ""; |
| 49 | + req.on("data", (chunk) => { |
| 50 | + data += chunk; |
| 51 | + }); |
| 52 | + req.on("end", () => { |
| 53 | + console.log(`\n${data}`); |
| 54 | + // client.close(); |
| 55 | + }); |
| 56 | + req.end(); |
| 57 | + } |
| 58 | +} |
0 commit comments