npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-ciopaas

v1.0.2

Published

AI智能语音客服交付对接SDK

Readme

ai-ciopaas

AI智能语音客服交付对接 SDK。当前封装了文档中的登录、子账号、话术模板、JSON 外呼任务接口,并提供挂机流水回调的 TypeScript 类型。

安装

pnpm add ai-ciopaas

在当前 monorepo 内使用:

pnpm --filter ai-ciopaas build

初始化

baseUrlapiAccessIdapiAccessSecret 都需要由接入项目在运行时传入。SDK 会自动调用 /api/login 获取并缓存 api_keyuser_sn,过期前会自动刷新。

import { createAiCioPaasClient } from 'ai-ciopaas';

const client = createAiCioPaasClient({
	baseUrl: 'https://xxx.xxx.com',
	apiAccessId: process.env.CIOPAAS_API_ACCESS_ID!,
	apiAccessSecret: process.env.CIOPAAS_API_ACCESS_SECRET!,
});

const session = await client.login();
console.log(session.userSn, session.apiKey);

运行中切换配置:

client.updateCredentials({
	baseUrl: 'https://new-ciopaas.example.com',
	apiAccessId: 'new-access-id',
	apiAccessSecret: 'new-access-secret',
});

子账号

const subAccounts = await client.subAccounts.list({
	pageIndex: 0,
	pageSize: 20,
	user_name: '',
});

await client.subAccounts.create({
	user_name: 'demo001',
	contact: 'demo001',
	password: 'Demo001A123',
	re_password: 'Demo001A123',
	organization_id: 173,
	role_id: 366,
	max_call_count: 1,
	project_sn: 'projects|xxx',
	sdzj_phone: 'vos:900002',
	display_phone: '',
	callin_project_sn: 'projects|xxx',
	ext: '1',
	linkext: '2',
	sippwd: 'Demo001A123',
	project_name: '测试话术',
	auto_create: 1,
});

await client.subAccounts.update({
	user_name: 'demo001',
	contact: 'demo001',
	password: '',
	re_password: '',
	organization_id: 173,
	role_id: 366,
	max_call_count: 1,
	project_sn: 'projects|xxx',
});

await client.subAccounts.remove(['demo001']);

话术模板

const projects = await client.rhetoric.listProjects();
// client.projects 是 client.rhetoric 的别名

新建或追加外呼任务

const task = await client.outboundTasks.createJsonTask({
	source: '新建任务1',
	project_sn: 'projects|xxx',
	ai_user_sn: 'SYSUSER|子账号sn',
	is_zidong: 'on',
	client_info_json: {
		data: [
			{
				姓名: '张三',
				电话: '13800000000',
				地址: '深圳',
			},
		],
	},
	yd_display_phone: 'SYSUSER|子账号sn@vos:900002',
});

await client.outboundTasks.appendJsonTask({
	dial_task_main_sn: task.dial_task_main_sn,
	source: '追加任务1',
	project_sn: 'projects|xxx',
	ai_user_sn: 'SYSUSER|子账号sn',
	client_info_json: {
		data: [{ 姓名: '李四', 电话: '13900000000' }],
	},
});

密文传输 client_info_json

await client.outboundTasks.createEncryptedJsonTask({
	source: '密文任务',
	project_sn: 'projects|xxx',
	ai_user_sn: 'SYSUSER|子账号sn',
	client_info_json: {
		data: [{ 姓名: '王五', 电话: '13700000000' }],
	},
});

任务导入模板

client_info_json 对应的模板可以直接从 /api/exportModel 获取。

获取 JSON 模板

const template = await client.outboundTasks.getImportTemplateJson({
	project_sn: 'projects|4a92f90b5339646b36e9805600820deb',
});

console.log(template);

直接下载 Excel 模板

const buffer = await client.outboundTasks.downloadImportTemplate({
	project_sn: 'projects|4a92f90b5339646b36e9805600820deb',
});
import { writeFile } from 'node:fs/promises';

await writeFile('import-template.xlsx', Buffer.from(buffer));

生成浏览器下载链接

const url = await client.outboundTasks.getImportTemplateDownloadUrl({
	project_sn: 'projects|4a92f90b5339646b36e9805600820deb',
});

console.log(url);

通用请求

如果后续文档新增接口,可以先用通用 post 方法接入。设置 auth: true 后会自动注入 api_keyuser_sn

const result = await client.post(
	'/api/someNewApi',
	{
		foo: 'bar',
	},
	{
		auth: true,
	},
);

错误处理

接口返回 code !== 0rst !== 200 时会抛出 AiCioPaasErrorapi_key 过期时默认会重新登录并重试一次。

import { AiCioPaasError } from 'ai-ciopaas';

try {
	await client.rhetoric.listProjects();
} catch (error) {
	if (error instanceof AiCioPaasError) {
		console.error(error.code, error.message, error.endpoint);
	}
}

回调响应

挂机流水回调处理成功后,需要返回字符串 SUCCESS

import {
	CIOPAAS_CALLBACK_SUCCESS,
	type OutboundTaskCallbackPayload,
} from 'ai-ciopaas';

export async function handleCallback(payload: OutboundTaskCallbackPayload) {
	// 建议按 payload.sn 或 payload.dial_task_main_sn 做幂等处理
	return CIOPAAS_CALLBACK_SUCCESS;
}