Add Support For Create Chat Session.

This commit is contained in:
sdk-team
2025-07-16 08:09:13 +00:00
parent 070025342e
commit 808e4da670
9 changed files with 581 additions and 1 deletions

View File

@@ -0,0 +1,89 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/lingmou/LingMouClient.h>
#include <alibabacloud/core/SimpleCredentialsProvider.h>
using namespace AlibabaCloud;
using namespace AlibabaCloud::Location;
using namespace AlibabaCloud::LingMou;
using namespace AlibabaCloud::LingMou::Model;
namespace
{
const std::string SERVICE_NAME = "LingMou";
}
LingMouClient::LingMouClient(const Credentials &credentials, const ClientConfiguration &configuration) :
RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
{
auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
}
LingMouClient::LingMouClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
RoaServiceClient(SERVICE_NAME, credentialsProvider, configuration)
{
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
}
LingMouClient::LingMouClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
{
auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
}
LingMouClient::~LingMouClient()
{}
LingMouClient::CreateChatSessionOutcome LingMouClient::createChatSession(const CreateChatSessionRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();
if (!endpointOutcome.isSuccess())
return CreateChatSessionOutcome(endpointOutcome.error());
auto outcome = makeRequest(endpointOutcome.result(), request);
if (outcome.isSuccess())
return CreateChatSessionOutcome(CreateChatSessionResult(outcome.result()));
else
return CreateChatSessionOutcome(outcome.error());
}
void LingMouClient::createChatSessionAsync(const CreateChatSessionRequest& request, const CreateChatSessionAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, createChatSession(request), context);
};
asyncExecute(new Runnable(fn));
}
LingMouClient::CreateChatSessionOutcomeCallable LingMouClient::createChatSessionCallable(const CreateChatSessionRequest &request) const
{
auto task = std::make_shared<std::packaged_task<CreateChatSessionOutcome()>>(
[this, request]()
{
return this->createChatSession(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/lingmou/model/CreateChatSessionRequest.h>
using AlibabaCloud::LingMou::Model::CreateChatSessionRequest;
CreateChatSessionRequest::CreateChatSessionRequest()
: RoaServiceRequest("lingmou", "2025-05-27") {
setResourcePath("/openapi/chat/init/[id]"};
setMethod(HttpRequest::Method::Post);
}
CreateChatSessionRequest::~CreateChatSessionRequest() {}
std::string CreateChatSessionRequest::getLicense() const {
return license_;
}
void CreateChatSessionRequest::setLicense(const std::string &license) {
license_ = license;
setParameter(std::string("license"), license);
}
std::string CreateChatSessionRequest::getInstanceId() const {
return instanceId_;
}
void CreateChatSessionRequest::setInstanceId(const std::string &instanceId) {
instanceId_ = instanceId;
setParameter(std::string("instanceId"), instanceId);
}
std::string CreateChatSessionRequest::getId() const {
return id_;
}
void CreateChatSessionRequest::setId(const std::string &id) {
id_ = id;
setParameter(std::string("id"), id);
}
std::string CreateChatSessionRequest::getPlatform() const {
return platform_;
}
void CreateChatSessionRequest::setPlatform(const std::string &platform) {
platform_ = platform;
setParameter(std::string("platform"), platform);
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/lingmou/model/CreateChatSessionResult.h>
#include <json/json.h>
using namespace AlibabaCloud::LingMou;
using namespace AlibabaCloud::LingMou::Model;
CreateChatSessionResult::CreateChatSessionResult() :
ServiceResult()
{}
CreateChatSessionResult::CreateChatSessionResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
CreateChatSessionResult::~CreateChatSessionResult()
{}
void CreateChatSessionResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
auto dataNode = value["data"];
if(!dataNode["sessionId"].isNull())
data_.sessionId = dataNode["sessionId"].asString();
auto rtcParamsNode = dataNode["rtcParams"];
if(!rtcParamsNode["appId"].isNull())
data_.rtcParams.appId = rtcParamsNode["appId"].asString();
if(!rtcParamsNode["avatarUserId"].isNull())
data_.rtcParams.avatarUserId = rtcParamsNode["avatarUserId"].asString();
if(!rtcParamsNode["channel"].isNull())
data_.rtcParams.channel = rtcParamsNode["channel"].asString();
if(!rtcParamsNode["clientUserId"].isNull())
data_.rtcParams.clientUserId = rtcParamsNode["clientUserId"].asString();
if(!rtcParamsNode["gslb"].isNull())
data_.rtcParams.gslb = rtcParamsNode["gslb"].asString();
if(!rtcParamsNode["nonce"].isNull())
data_.rtcParams.nonce = rtcParamsNode["nonce"].asString();
if(!rtcParamsNode["serverUserId"].isNull())
data_.rtcParams.serverUserId = rtcParamsNode["serverUserId"].asString();
if(!rtcParamsNode["timestamp"].isNull())
data_.rtcParams.timestamp = std::stol(rtcParamsNode["timestamp"].asString());
if(!rtcParamsNode["token"].isNull())
data_.rtcParams.token = rtcParamsNode["token"].asString();
auto avatarAssetsNode = dataNode["avatarAssets"];
if(!avatarAssetsNode["url"].isNull())
data_.avatarAssets.url = avatarAssetsNode["url"].asString();
if(!avatarAssetsNode["md5"].isNull())
data_.avatarAssets.md5 = avatarAssetsNode["md5"].asString();
if(!avatarAssetsNode["secret"].isNull())
data_.avatarAssets.secret = avatarAssetsNode["secret"].asString();
if(!avatarAssetsNode["type"].isNull())
data_.avatarAssets.type = avatarAssetsNode["type"].asString();
if(!avatarAssetsNode["minRequiredVersion"].isNull())
data_.avatarAssets.minRequiredVersion = avatarAssetsNode["minRequiredVersion"].asString();
if(!value["requestId"].isNull())
requestId_ = value["requestId"].asString();
if(!value["message"].isNull())
message_ = value["message"].asString();
if(!value["httpStatusCode"].isNull())
httpStatusCode_ = std::stol(value["httpStatusCode"].asString());
if(!value["code"].isNull())
code_ = value["code"].asString();
if(!value["success"].isNull())
success_ = value["success"].asString() == "true";
}
std::string CreateChatSessionResult::getRequestId()const
{
return requestId_;
}
std::string CreateChatSessionResult::getMessage()const
{
return message_;
}
long CreateChatSessionResult::getHttpStatusCode()const
{
return httpStatusCode_;
}
CreateChatSessionResult::Data CreateChatSessionResult::getData()const
{
return data_;
}
std::string CreateChatSessionResult::getCode()const
{
return code_;
}
bool CreateChatSessionResult::getSuccess()const
{
return success_;
}