Integrating Contentful with LivePerson knowledge bases

Illustration of a number of books laying about, signifying integrating Contentful with LivePerson knowledge bases
Published
October 20, 2021
Category

Developers

In this tutorial, we’ll show you how to build a knowledge base in LivePerson that pulls content from Contentful. With this integration, you will use content that is organized and managed in Contentful’s centralized content hub to power knowledge bases. This will provide more brand consistency in your knowledge bases.

LivePerson’s Knowledge AI enables brands to expose their FAQs to end-users, based on the trained domain and can be integrated with the LivePerson bots ecosystem. Learn more LivePerson knowledge bases.

Before we get started

To complete this tutorial you will need the following:

Create your content model within Contentful

To get started, we’ll create a simple content model in Contentful. The  content model represents the content types you plan to create. 

Learn about models, content types and fields in Contentful

In this example, we will only use the four fields required by the knowledge base and we’ll use the same content type for metadata and content.  The fields we’ll need are:

  • External id: A string; unique ID assigned to the article.

  • Title: The article title. This should be a complete sentence or question that the user might ask.

  • Tags:  A list of relevant keywords. These highlight the key noun(s) or word(s) in the training phrases. For example, for an article about health insurance, the tags should be "health," “insurance,” “benefits.” These should be words, not sentences.

  • Summary:  A short response or message to be sent to the user. If you include a web link, be aware that it might not display correctly across all channels. For channels, like SMS/Messaging, that send HTML as plain text, you might need to show the URL by itself, not wrapped in HTML.

Prepare delivery the API endpoint in Contentful

To pull the content into a LivePerson knowledge base from Contentful, we need a Content Delivery API endpoint similar to this: 

curl --include \
     --request GET \
     https://cdn.contentful.com/spaces/{space_id}/environments/{environment_id}/entries?content_type={content_type}access_token={access_token}

A Content Delivery API is a read-only API for delivering content from Contentful to apps, websites and other media. Content is delivered as JSON data. Images, videos and other media are delivered as files. The API can return up to 1,000 entries in one result. If your knowledge base has more, you can write a middle layer to fetch entries and cache them.

Using this endpoint, we can fetch all the entries of a specific content type, which is precisely what we need for LivePerson knowledge base.

Create a knowledge base within LivePerson

Next, we’ll need to create a new knowledge base within LivePerson.

GIF showing how to log into liveperson and get started on creating a new knowledgebase

Log into LivePerson and go to Conversational AI > Knowledge AI > Add Knowledge Base > External Knowledge Base.

GIF showing how to create a new knowledgebase in liveperson

Provide a knowledge base name, select  “other” as the content provider and select the domain relevant to your use case. 

Provide a knowledge base name, select  “other” as the content provider and select the domain relevant to your use case.

Connect Contentful to your LivePerson knowledge base

After creating the knowledge base, go to Get Content Metadata. Provide the endpoint for the Content Delivery API from the previous step and the JOLT spec to map Contentful JSON to the LivePerson knowledge base. We’ll cover this in more detail below and there is additional information on JOLT spec and mapping content in LivePerson available.

Gif showing how to connect liveperson knowledgebase to Contentful

Below is the JOLT spec for our use case. In this step, we are fetching content metadata for all the content from Contentful, which includes external id, title and tags. 

Content Delivery API:

{
  "sys": {
    "type": "Array"
  },
  "total": 5,
  "skip": 0,
  "limit": 100,
  "items": [
    {
      "metadata": {
        "tags": []
      },
      "sys": {
        "space": {
          "sys": {
            "type": "Link",
            "linkType": "Space",
            "id": "1vt6sxbf70mi"
          }
        },
        "id": "6w52ty0QnhroyFeOusBxeQ",
        "type": "Entry",
        "createdAt": "2021-05-18T14:02:16.627Z",
        "updatedAt": "2021-06-21T13:20:04.304Z",
        "environment": {
          "sys": {
            "id": "master",
            "type": "Link",
            "linkType": "Environment"
          }
        },
        "revision": 7,
        "contentType": {
          "sys": {
            "type": "Link",
            "linkType": "ContentType",
            "id": "LivePersonKbDemo"
          }
        },
        "locale": "en-GB"
      },
      "fields": {
        "externalId": "article_2_id",
        "title": "My account's been disabled, what can I do?",
        "tags": [
          "tag1",
          "tag2"
        ],
        "summary": "Please call our free hotline 8800"
      }
    }
  ]
}

JOLT spec:

[
 {
  "operation": "shift",
  "spec": {
   "items": {
    "*": {
     "fields": {
      "externalId": "externalId",
      "title": "title",
      "summary": "summary"
     }
    }
   }
  }
 }
]

Now we will go to Get Content and repeat the same process with the JOLT spec below. In this step, we are fetching the content based on the external id. For simplicity we are just mapping title, summary and external id. You can map more fields as needed for your use case.

Content Delivery API:

{
  "sys": {
    "type": "Array"
  },
  "total": 5,
  "skip": 0,
  "limit": 100,
  "items": [
    {
      "metadata": {
        "tags": []
      },
      "sys": {
        "space": {
          "sys": {
            "type": "Link",
            "linkType": "Space",
            "id": "1vt6sxbf70mi"
          }
        },
        "id": "6w52ty0QnhroyFeOusBxeQ",
        "type": "Entry",
        "createdAt": "2021-05-18T14:02:16.627Z",
        "updatedAt": "2021-06-21T13:20:04.304Z",
        "environment": {
          "sys": {
            "id": "master",
            "type": "Link",
            "linkType": "Environment"
          }
        },
        "revision": 7,
        "contentType": {
          "sys": {
            "type": "Link",
            "linkType": "ContentType",
            "id": "LivePersonKbDemo"
          }
        },
        "locale": "en-GB"
      },
      "fields": {
        "externalId": "article_2_id",
        "title": "My account's been disabled, what can I do?",
        "tags": [
          "tag1",
          "tag2"
        ],
        "summary": "Please call our free hotline 8800"
      }
    }
  ]
}

JOLT spec:

[
 {
  "operation": "shift",
  "spec": {
   "items": {
    "*": {
     "fields": {
      "externalId": "externalId",
      "title": "title",
      "summary": "summary"
     }
    }
   }
  }
 }
]

If you need more detail, LivePerson provides information on setting up external knowledge bases

Pull your content into the knowledge base 

Once you have completed these steps, use the Sync Articles button to pull the content from Contentful into the LivePerson knowledge base you created.

Screenshot highlighting where the sync articles button is in liveperson

Go to the Articles tab, to see all the content that is pulled from Contentful.

Screenshot of where to see the content being pulled in liveperson

Now you have successfully created an external knowledge base in LivePerson that pulls content from Contentful.

Learn more about using Contentful to centralize knowledge base content.

About the author

Don't miss the latest

Get updates in your inbox
Discover new insights from the Contentful developer community each month.
add-circle arrow-right remove style-two-pin-marker subtract-circle