有了android studio中的Assistant java API版本,我有了很好的经验,它可以正常工作。
我的环境:
离子CLI:5.0.1
离子框架:@ ionic / angular 4.4.2
现在,我正在使用ionic4尝试使用Assistant V2 API(节点版本:https://cloud.ibm.com/apidocs/assistant-v2?code=node)将请求发送到Watson Assistant,并且发现错误:
[ng] ERROR in ./node_modules/dotenv/lib/main.js [ng] Module not found: Error: Can't resolve 'fs' in 'C:\Path\Chatbot\node_modules\dotenv\lib' [ng] ERROR in ./node_modules/ibm-cloud-sdk-core/lib/read-credentials-file.js
home.page.ts
import { Component } from '@angular/core';
//const AssistantV2 = require('ibm-watson/assistant/v2');
import * as AssistantV2 from 'ibm-watson/assistant/v2';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
assistant: AssistantV2;
api_key;
url;
assistant_id;
constructor() {
this.api_key = '{my_apikey}'
this.url = 'https://gateway.watsonplatform.net/assistant/api'
this.version = '2019-02-28';
this.assistant_id = "{my_assistantid}";
this.assistant = new AssistantV2({
iam_apikey: this.api_key,
version: '2019-02-28',
url: this.url
});