Knowledge provides your Assistant with access to unstructured data sources. This API allows you to programatically upload Knowledge for your Assistant to consume.
The SID of the Account that created the Knowledge resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The status of processing the knowledge source ('QUEUED', 'PROCESSING', 'COMPLETED', 'FAILED')
The date and time in GMT when the Knowledge was created specified in ISO 8601 format.
POST https://assistants.twilio.com/v1/Knowledge
application/json
The policy associated with the knowledge source.
The type of the knowledge source.
You can configure Knowledge sources of type: Web
, Text
, and File
from the API.
Give your Assistant a publicly-accessible URL to index information from. See additional details about web crawling limits.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createKnowledge() {11const knowledge = await client.assistants.v1.knowledge.create({12name: "Info about Twilio Alpha",13type: "Web",14description: "Use this for information about Twilio Alpha or AI Assistants",15knowledge_source_details: {16source: "https://twilioalpha.com",17},18});1920console.log(knowledge.description);21}2223createKnowledge();
Provide plain text for your Assistant.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createKnowledge() {11const knowledge = await client.assistants.v1.knowledge.create({12name: "Star Wars Quotes",13type: "Text",14description: "Use this for famous Star Wars quotes",15knowledge_source_details: {16content: "This is the ship that made the Kessel Run in fourteen parsecs?",17},18});1920console.log(knowledge.description);21}2223createKnowledge();
Upload a file for your Assistant to reference. See supported file types.
1const fs = require('fs');2// Before running this code, install "form-data" and "axios" using `npm install form-data axios`3const FormData = require('form-data');4const axios = require('axios');56// Provision API Keys at twilio.com/console/runtime/api-keys7// and set the environment variables. See http://twil.io/secure8const apiKey = process.env.TWILIO_API_KEY;9const apiSecret = process.env.TWILIO_API_SECRET;1011const uploadUrl = `https://assistants-upload.twilio.com/v1/Knowledge/Upload`;1213const form = new FormData();14form.append('name', 'File Demo');15form.append('description', 'A description of this file')16form.append('type', 'File');17form.append('assistant_id', 'aia_asst_xxxxxxxxxxxxxxxx');18form.append('file_0', fs.createReadStream('README.md'), {19contentType: 'text/markdown',20});2122// Create a new Function Version23axios24.post(uploadUrl, form, {25auth: {26username: apiKey,27password: apiSecret,28},29headers: form.getHeaders(),30})31.then((response) => {32const newKnowledgeId = response.data.id;33console.log(newKnowledgeId);34});
GET https://assistants.twilio.com/v1/Knowledge/{id}
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchKnowledge() {11const knowledge = await client.assistants.v1.knowledge("id").fetch();1213console.log(knowledge.description);14}1516fetchKnowledge();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"date_created": "2009-07-06T20:30:00Z",4"date_updated": "2009-07-06T20:30:00Z",5"description": "description",6"id": "id",7"knowledge_source_details": {},8"name": "name",9"status": "status",10"type": "type",11"url": "url"12}
GET https://assistants.twilio.com/v1/Knowledge
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listKnowledge() {11const knowledge = await client.assistants.v1.knowledge.list({ limit: 20 });1213knowledge.forEach((k) => console.log(k.description));14}1516listKnowledge();
1{2"knowledge": [3{4"description": "description",5"id": "aia_know",6"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",7"knowledge_source_details": {},8"name": "name",9"status": "status",10"type": "type",11"url": "url",12"date_created": "2009-07-06T20:30:00Z",13"date_updated": "2009-07-06T20:30:00Z"14}15],16"meta": {17"first_page_url": "https://www.example.com",18"key": "key",19"next_page_url": "https://www.example.com",20"page": 42,21"page_size": 42,22"previous_page_url": "https://www.example.com",23"url": "https://www.example.com"24}25}