UNPKG

1.53 kBPlain TextView Raw
1/**
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License.
4 */
5import * as Request from 'request'
6import { CLDebug } from './CLDebug'
7
8export class AzureFunctions {
9 public static Call(azureFunctionsUrl: string, azureFunctionsKey: string, funcName: string, args: string): Promise<string> {
10 let apiPath = 'app'
11
12 if (azureFunctionsKey) {
13 if (args) {
14 args += `&code=${azureFunctionsKey}`
15 } else {
16 args = `?code=${azureFunctionsKey}`
17 }
18 }
19 return new Promise((resolve, reject) => {
20 const requestData = {
21 url: azureFunctionsUrl + funcName + '/' + args,
22 /* TODO - auth
23 headers: {
24 'Cookie' : this.credentials.Cookiestring(),
25 },*/
26 /* TODO - params
27 body: {
28 name: name,
29 LuisAuthKey: luisKey
30 },
31 */
32 json: true
33 }
34 CLDebug.LogRequest('GET', apiPath, requestData)
35 Request.get(requestData, (error, response, body) => {
36 if (error) {
37 reject(error)
38 } else if (response.statusCode && response.statusCode >= 300) {
39 reject(body)
40 } else {
41 resolve(body.Result)
42 }
43 })
44 })
45 }
46}