// HaiChat SDK for JavaScript
const HaiChat = require('haichat-sdk');
const client = new HaiChat.Client({
apiKey: 'your-api-key',
environment: 'sandbox'
});
// チャットボットとの会話
async function chatWithBot(message) {
try {
const response = await client.chat.send({
message: message,
userId: 'user123'
});
console.log(response.reply);
} catch (error) {
console.error('Error:', error.message);
}
}
chatWithBot('こんにちは!');
# HaiChat SDK for Python
from haichat import HaiChatClient
client = HaiChatClient(
api_key='your-api-key',
environment='sandbox'
)
# チャットボットとの会話
def chat_with_bot(message):
try:
response = client.chat.send(
message=message,
user_id='user123'
)
print(response.reply)
except Exception as e:
print(f'Error: {e}')
chat_with_bot('こんにちは!')
<?php
// HaiChat SDK for PHP
require_once 'vendor/autoload.php';
use HaiChat\HaiChatClient;
$client = new HaiChatClient([
'api_key' => 'your-api-key',
'environment' => 'sandbox'
]);
// チャットボットとの会話
function chatWithBot($message) {
global $client;
try {
$response = $client->chat->send([
'message' => $message,
'user_id' => 'user123'
]);
echo $response->reply;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
chatWithBot('こんにちは!');
?>
// HaiChat SDK for Java
import com.haichat.HaiChatClient;
import com.haichat.models.ChatRequest;
import com.haichat.models.ChatResponse;
public class HaiChatExample {
public static void main(String[] args) {
HaiChatClient client = new HaiChatClient.Builder()
.apiKey("your-api-key")
.environment("sandbox")
.build();
// チャットボットとの会話
try {
ChatRequest request = new ChatRequest.Builder()
.message("こんにちは!")
.userId("user123")
.build();
ChatResponse response = client.chat().send(request);
System.out.println(response.getReply());
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}