@uveysservetoglu/kobil-chat
v1.0.0
Published
KOBIL Chat (Mercury) client for Node.js: send text, multi-choice and SmartScreen messages, send attachments and download media, with automatic OAuth token management.
Downloads
148
Maintainers
Readme
@uveysservetoglu/kobil-chat
KOBIL Chat (Mercury) client for Node.js / TypeScript, with automatic OAuth token management.
npm install @uveysservetoglu/kobil-chatimport { ChatClient } from "@uveysservetoglu/kobil-chat";
const chat = new ChatClient({
// credentials (or KOBIL_* env vars):
tokenEndpoint: process.env.KOBIL_TOKEN_ENDPOINT!,
clientId: process.env.KOBIL_CLIENT_ID!,
clientSecret: process.env.KOBIL_CLIENT_SECRET!,
tokenAuthMode: "basic", // the chat token endpoint may require Basic auth
// chat-specific:
chatBaseUrl: "https://idp.cloud.kobil.com/auth/realms/{TENANT}/mpower/v1/users/{USER_ID}",
tenantName: "acme",
mediaDownloadUrl: "https://idp.cloud.kobil.com/v1/mpower/tenants/{TENANT}/media/{MEDIA_ID}/download",
});{TENANT} is filled from tenantName, {USER_ID} from the call, {MEDIA_ID} from
getAttachmentFile. /message or /media is appended to chatBaseUrl per operation.
Message text supports styling: *bold*, _italic_, ~strike~, \n.
The five operations
// 1. Plain text
await chat.sendText({ userId, text: "Hi, how are you?", title: "Update" });
// 2. Multi-choice
await chat.sendChoice({ userId, text: "Continue?", choices: ["Yes", "No"] });
// 3. SmartScreen
await chat.sendSmartScreen({ userId, text: "Opening…", smartScreenServiceUuid: "service_client_id" });
// 4. Attachment (content type inferred from the file name)
await chat.sendAttachment({ userId, file: pdfBytes, fileName: "agreement.pdf", text: "Please review" });
// 5. Download media
const bytes = await chat.getAttachmentFile(mediaId);All send operations return { messageId, instanceId }. JavaScript usage is identical
(const { ChatClient } = require("@uveysservetoglu/kobil-chat")).
Errors
Failures throw KobilChatError (extends KobilError) with statusCode / responseBody.
License
MIT
