Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/luis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@
"@oclif/command": "~1.5.19",
"@oclif/config": "~1.13.3",
"@oclif/errors": "~1.2.2",
"@types/node-fetch": "~2.5.5",
"@types/sinon": "^7.5.0",
"cli-ux": "~5.3.3",
"fs-extra": "^8.1.0",
"lodash": "^4.17.15",
"node-fetch": "~2.6.0",
"tslib": "^1.10.0",
"username": "^4.1.0"
},
Expand Down
19 changes: 16 additions & 3 deletions packages/luis/src/commands/luis/application/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,28 @@ export default class LuisApplicationImport extends Command {
const appJSON = stdin ? stdin : await utils.getInputFromFile(inVal)
if (!appJSON) throw new CLIError('No import data found - please provide input through stdin or the --in flag')

const client = utils.getLUISClient(subscriptionKey, endpoint)
// const client = utils.getLUISClient(subscriptionKey, endpoint)

const options: any = {}
if (name) options.appName = name

try {
const response = await client.apps.importMethod(JSON.parse(appJSON), options)
// const response = await client.apps.importMethod(JSON.parse(appJSON), options)

const output: string = flags.json ? JSON.stringify({Status: 'Success', id: response.body}, null, 2) : `App successfully imported with id ${response.body}.`
name = name ? '?appName=' + name : ''
let url = endpoint + '/luis/authoring/v3.0-preview/apps/import' + name
const headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscriptionKey
}
const response = await fetch(url, {method: 'POST', headers, body: appJSON})
const messageData = await response.json()

if (messageData.error) {
throw new CLIError(messageData.error.message)
}

const output: string = flags.json ? JSON.stringify({Status: 'Success', id: messageData}, null, 2) : `App successfully imported with id ${messageData}.`
this.log(output)

if (flags.save) {
Expand Down
22 changes: 18 additions & 4 deletions packages/luis/src/commands/luis/version/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import {CLIError, Command, flags} from '@microsoft/bf-cli-command'

import fetch from 'node-fetch'
const utils = require('../../../utils/index')

export default class LuisVersionImport extends Command {
Expand Down Expand Up @@ -44,11 +44,25 @@ export default class LuisVersionImport extends Command {

if (versionId) options.versionId = versionId

const client = utils.getLUISClient(subscriptionKey, endpoint)
// const client = utils.getLUISClient(subscriptionKey, endpoint)

try {
const response = await client.versions.importMethod(appId, JSON.parse(appJSON), options)
const output = flags.json ? JSON.stringify({Status: 'Success', version: response.body}, null, 2) : `App version successfully imported as version ${response.body}.`
// const response = await client.versions.importMethod(appId, JSON.parse(appJSON), options)

versionId = versionId ? '?versionId=' + versionId : ''
let url = endpoint + '/luis/authoring/v3.0-preview/apps/' + appId + '/versions/import' + versionId
const headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscriptionKey
}
const response = await fetch(url, {method: 'POST', headers, body: appJSON})
const messageData = await response.json()

if (messageData.error) {
throw new CLIError(messageData.error.message)
}

const output = flags.json ? JSON.stringify({Status: 'Success', version: messageData}, null, 2) : `App version successfully imported as version ${messageData}.`
this.log(output)
} catch (err) {
throw new CLIError(`Failed to import app version: ${err}`)
Expand Down