generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
337 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# summary | ||
|
||
Open an agent in the Agent Builder org UI in a browser. | ||
|
||
# description | ||
|
||
Use the --name flag to open an agent using the developer name (aka API name) in the Agent Builder Org UI. | ||
|
||
To generate a URL but not launch it in your browser, specify --url-only. | ||
|
||
To open in a specific browser, use the --browser flag. Supported browsers are "chrome", "edge", and "firefox". If you don't specify --browser, the org opens in your default browser. | ||
|
||
# examples | ||
|
||
- Open the agent with developer name "Coral_Cloud_Agent using the default browser: | ||
|
||
$ <%= config.bin %> <%= command.id %> --name Coral_Cloud_Agent | ||
|
||
- Open the agent in an incognito window of your default browser: | ||
|
||
$ <%= config.bin %> <%= command.id %> --private --name Coral_Cloud_Agent | ||
|
||
- Open the agent in the org with alias MyTestOrg1 using the Firefox browser: | ||
|
||
$ <%= config.bin %> <%= command.id %> --target-org MyTestOrg1 --browser firefox --name Coral_Cloud_Agent | ||
|
||
# flags.name.summary | ||
|
||
The developer name (aka API name) of the agent to open in the Agent Builder org UI. | ||
|
||
# flags.private.summary | ||
|
||
Open the org in the default browser using private (incognito) mode. | ||
|
||
# flags.browser.summary | ||
|
||
Browser where the org opens. | ||
|
||
# flags.url-only.summary | ||
|
||
Display navigation URL, but don’t launch browser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/OrgOpenOutput", | ||
"definitions": { | ||
"OrgOpenOutput": { | ||
"type": "object", | ||
"properties": { | ||
"url": { | ||
"type": "string" | ||
}, | ||
"username": { | ||
"type": "string" | ||
}, | ||
"orgId": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["url", "username", "orgId"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { Flags } from '@salesforce/sf-plugins-core'; | ||
import { Connection, Messages } from '@salesforce/core'; | ||
import { buildFrontdoorUrl } from '../../../shared/orgOpenUtils.js'; | ||
import { OrgOpenCommandBase } from '../../../shared/orgOpenCommandBase.js'; | ||
import { type OrgOpenOutput } from '../../../shared/orgTypes.js'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-org', 'open.agent'); | ||
|
||
export class OrgOpenAgent extends OrgOpenCommandBase<OrgOpenOutput> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
|
||
public static readonly flags = { | ||
'target-org': Flags.requiredOrg(), | ||
'api-version': Flags.orgApiVersion(), | ||
name: Flags.string({ | ||
char: 'n', | ||
summary: messages.getMessage('flags.name.summary'), | ||
required: true, | ||
}), | ||
private: Flags.boolean({ | ||
summary: messages.getMessage('flags.private.summary'), | ||
exclusive: ['url-only', 'browser'], | ||
}), | ||
browser: Flags.option({ | ||
char: 'b', | ||
summary: messages.getMessage('flags.browser.summary'), | ||
options: ['chrome', 'edge', 'firefox'] as const, // These are ones supported by "open" package | ||
exclusive: ['url-only', 'private'], | ||
})(), | ||
'url-only': Flags.boolean({ | ||
char: 'r', | ||
summary: messages.getMessage('flags.url-only.summary'), | ||
aliases: ['urlonly'], | ||
deprecateAliases: true, | ||
}), | ||
}; | ||
|
||
public async run(): Promise<OrgOpenOutput> { | ||
const { flags } = await this.parse(OrgOpenAgent); | ||
this.org = flags['target-org']; | ||
this.connection = this.org.getConnection(flags['api-version']); | ||
|
||
const [frontDoorUrl, retUrl] = await Promise.all([ | ||
buildFrontdoorUrl(this.org, this.connection), | ||
buildRetUrl(this.connection, flags.name), | ||
]); | ||
|
||
return this.openOrgUI(flags, frontDoorUrl, retUrl); | ||
} | ||
} | ||
|
||
// Build the URL part to the Agent Builder given a Bot API name. | ||
const buildRetUrl = async (conn: Connection, botName: string): Promise<string> => { | ||
const query = `SELECT id FROM BotDefinition WHERE DeveloperName='${botName}'`; | ||
const botId = (await conn.singleRecordQuery<{ Id: string }>(query)).Id; | ||
return `AiCopilot/copilotStudio.app#/copilot/builder?copilotId=${botId}`; | ||
}; |
Oops, something went wrong.