README
xs:code VSCode chat SDK npm package
If you are developing a VSCode extension, you can easily add xs:code's chat and search features as a built in feature in your extension. xs:code Chat allows your users to chat with xs:code Aces directly from VSCode, and get paid support for any coding problem.
For more information about integrating xs:code into your product, see: https://xscode.com/api-integration
Getting started
First install the package
npm install xscode-sdk
On the extension.ts
file add the following code:
import {XScodeChatPanel} from 'xscode-sdk';
To open the chat panel, use the following code:
export function activate(context: vscode.ExtensionContext) {
// register xscode-sdk
XScodeChatPanel.registerChat(context);
context.subscriptions.push(
vscode.commands.registerCommand('xscodeChat.open', async () => {
const xsToken: string = context.globalState.get('xsToken') || '';
const searchTerm: string = context.globalState.get('xsTerm') || '';
if (!xsToken) {
XScodeChatPanel.authenticationWithXScode(context);
} else {
XScodeChatPanel.createOrShow(context, searchTerm, vendorId);
}
}),
vscode.commands.registerCommand('xscodeChat.close', async () => {
XScodeChatPanel.unRegisterChat(context);
})
);
See "methods" for information about the methods used in this code snippet and their parameters.
For example, to add a hover element to open the chat widget with a mouse click, use this code:
vscode.languages.registerHoverProvider(
['*'],
new class implements vscode.HoverProvider {
provideHover(
_document: vscode.TextDocument,
_position: vscode.Position,
_token: vscode.CancellationToken
): vscode.ProviderResult<vscode.Hover> {
const commentCommandUri = vscode.Uri.parse(`command:xscodeChat.open`);
const contents = new vscode.MarkdownString(`need help? [Chat with an Expert](${commentCommandUri})`);
contents.isTrusted = true;
return new vscode.Hover(contents);
}
}()
);
Methods
The are 4 available methods on XScodeChatPanel:
Register
registerChat()
will register the xscode-sdk and listen to the response token from authentication.
Syntax: XScodeChatPanel.registerChat(context);
Authentication
authenticationWithXScode()
opens xscode.com for authenticating users.
Syntax: XScodeChatPanel.authenticationWithXScode(context);
Create or show the chat panel
createOrShow()
opens the chat panel inside vscode.
Syntax: XScodeChatPanel.createOrShow(context, searchTerm, vendorId);
Parameters:
- searchTerm - You can pass the
searchTerm
parameter to open the chat in search mode with the specific keywords. Pass one string with several keywords separated by spaces.If thesearchTerm
is not passed, the chat will open in its default mode. See "search terms" below for more information. - vendorId - To be eligble for revenue sharing, you need to pass a vendor id provided by xs:code. See "Vendor ID" below for more information.
Logout and close the chat panel
unRegisterChat()
will log-out the user and close the chat panel.
Syntax: XScodeChatPanel.unRegisterChat(context);
Search terms
The xs:code SDK expects one or more (up to 5) topics of expertise, and will retrieve the best matches for those topics. More topics will retrieve better, more focused results. The topic list is quiet extensive (more than 7,000 topics and growing by the day), and includes most programming languages, frameworks, databases, programming concepts and open source products. We suggest running a few test queries before implementation, to see what results you are getting and adjust the topics (and how many of them you are sending as a query) to fit your specific needs.
Vendor ID and revenue sharing
To be eligible for revenue sharing from users who made purchases via your extension, you'll need to submit a valid vendor id
when opening the chat widget with the createOrShow()
command.
Please apply for a vendor id at: https://xscode.com/api-partner-registration/
Support
For help with integrating xs:code in your extension, contact support at support@xscode.com