1 /*
2 * Copyright (C) 2021-2023 Alibaba Group Holding Limited
3 */
4
5 #include <iostream>
6 #include <string.h>
7 #include "alibabacloud/core/AlibabaCloud.h"
8 #include "alibabacloud/core/CommonClient.h"
9 #include "model/common.h"
10
11 extern "C" {
12 using namespace std;
13 using namespace AlibabaCloud;
14
15 /*recognizing identity card has issue to be resolved*/
chatbot(char * pInstanceId,char * pSessionId,char * text)16 char *chatbot(char *pInstanceId, char *pSessionId, char *text)
17 {
18 InitializeSdk();
19 string key = getAccessKey();
20 string secret = getAccessSecret();
21 string instanceId = pInstanceId;
22 string utterance = text;
23 ClientConfiguration configuration;
24 configuration.setRegionId(CLOUD_AI_REGION_ID);
25 configuration.setEndpoint(CLOUD_AI_CHATBOT_ENDPOINT);
26 CommonClient client(key, secret, configuration);
27 CommonRequest request(CommonRequest::RpcPattern);
28 char *response = NULL;
29
30 request.setScheme("http");
31 request.setDomain(CLOUD_AI_CHATBOT_ENDPOINT);
32 request.setHttpMethod(HttpRequest::Get);
33 request.setQueryParameter("Action", "Chat");
34 request.setVersion("2017-10-11");
35 request.setQueryParameter("InstanceId", instanceId);
36 request.setQueryParameter("Utterance", utterance);
37 request.setQueryParameter("AccessKeyId", key);
38 if (pSessionId) {
39 string sessionId = pSessionId;
40 request.setQueryParameter("SessionId", sessionId);
41 }
42
43 auto outcome = client.commonResponse(request);
44 if (!outcome.isSuccess()) {
45 cout << "error code: " << outcome.error().errorCode() << endl;
46 cout << "error message: " << outcome.error().errorMessage() << endl;
47 cout << "error host: " << outcome.error().host() << endl;
48 cout << "error requestId: " << outcome.error().requestId() << endl;
49 cout << "error detail: " << outcome.error().detail() << endl;
50 ShutdownSdk();
51 return NULL;
52 }
53 cout << endl << "add item returns: " << outcome.result().payload() << endl << endl;
54 response = strdup(outcome.result().payload().c_str());
55 ShutdownSdk();
56
57 return response;
58 }
59
60 }