Seiten mit der API verwalten

In den meisten Fällen werden sie über die Console verwaltet. In komplexeren Szenarien möchten Sie Intents aber möglicherweise mit der API verwalten. In dieser Anleitung wird beschrieben, wie Sie Seiten mithilfe der API erstellen, auflisten und löschen können.

Seite erstellen

Zur Erstellung einer Seite für Ihren Agent rufen Sie die Methode create vom Typ Page auf.

Wählen Sie ein Protokoll und eine Version für die Seitenreferenz aus:

Protokoll V3 V3beta1
REST Seitenressource Seitenressource
RPC Benutzeroberfläche der Seite Benutzeroberfläche der Seite
C++ PagesClient Nicht verfügbar
C# PagesClient Nicht verfügbar
Einfach loslegen (Go) PagesClient Nicht verfügbar
Java PagesClient PagesClient
Node.js PagesClient PagesClient
PHP Nicht verfügbar Nicht verfügbar
Python PagesClient PagesClient
Ruby Nicht verfügbar Nicht verfügbar

Java

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

import com.google.cloud.dialogflow.cx.v3.CreatePageRequest;
import com.google.cloud.dialogflow.cx.v3.Page;
import com.google.cloud.dialogflow.cx.v3.PagesClient;
import java.io.IOException;

public class CreateSimplePage {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String agentId = "my-agent-id";
    String flowId = "my-flow-id";
    String location = "my-location";
    String displayName = "my-display-name";

    createPage(projectId, agentId, flowId, location, displayName);
  }

  // DialogFlow API Create Page Sample.
  // Creates a page from the provided parameters
  public static Page createPage(
      String projectId, String agentId, String flowId, String location, String displayName)
      throws IOException {
    Page response;
    CreatePageRequest.Builder createRequestBuilder = CreatePageRequest.newBuilder();
    Page.Builder pageBuilder = Page.newBuilder();

    pageBuilder.setDisplayName(displayName);

    createRequestBuilder
        .setParent(
            "projects/"
                + projectId
                + "/locations/"
                + location
                + "/agents/"
                + agentId
                + "/flows/"
                + flowId)
        .setPage(pageBuilder);

    // Make API request to create page
    // Note: close() needs to be called on the PagesClient object to clean up resources
    // such as threads. In the example below, try-with-resources is used,
    // which automatically calls close().
    try (PagesClient client = PagesClient.create()) {
      response = client.createPage(createRequestBuilder.build());
      System.out.println("Successfully created page!");
      return response;
    }
  }

Node.js

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

async function createPage(projectId, agentId, flowId, location, displayName) {
  const pagesClient = new PagesClient();

  const createPageRequest = {
    parent: `projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}`,
    page: {
      displayName: displayName,
    },
  };

  const response = await pagesClient.createPage(createPageRequest);
  console.log(response);
}

Python

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

async def create_page(project_id, agent_id, flow_id, location, displayName):
    pages_client = PagesAsyncClient()

    page = Page()
    page.display_name = displayName

    request = CreatePageRequest()
    request.parent = (
        "projects/"
        + project_id
        + "/locations/"
        + location
        + "/agents/"
        + agent_id
        + "/flows/"
        + flow_id
    )
    request.page = page

    response = await pages_client.create_page(request=request)
    return response

Seiten auflisten

Wenn Sie die Seiten für den Agent auflisten möchten, rufen Sie die Methode list für den Typ Page auf.

Wählen Sie ein Protokoll und eine Version für die Seitenreferenz aus:

Protokoll V3 V3beta1
REST Seitenressource Seitenressource
RPC Benutzeroberfläche der Seite Benutzeroberfläche der Seite
C++ PagesClient Nicht verfügbar
C# PagesClient Nicht verfügbar
Einfach loslegen (Go) PagesClient Nicht verfügbar
Java PagesClient PagesClient
Node.js PagesClient PagesClient
PHP Nicht verfügbar Nicht verfügbar
Python PagesClient PagesClient
Ruby Nicht verfügbar Nicht verfügbar

Java

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

import com.google.cloud.dialogflow.cx.v3.ListPagesRequest;
import com.google.cloud.dialogflow.cx.v3.ListPagesRequest.Builder;
import com.google.cloud.dialogflow.cx.v3.Page;
import com.google.cloud.dialogflow.cx.v3.PagesClient;
import java.io.IOException;

public class ListPages {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String agentId = "my-agent-id";
    String flowId = "my-flow-id";
    String location = "my-location";

    listPages(projectId, agentId, flowId, location);
  }

  // DialogFlow API List Pages Sample.
  // Lists all pages from the provided parameters
  public static void listPages(String projectId, String agentId, String flowId, String location)
      throws IOException {
    // Note: close() needs to be called on the PagesClient object to clean up resources
    // such as threads. In the example below, try-with-resources is used,
    // which automatically calls close().
    try (PagesClient client = PagesClient.create()) {
      Builder listRequestBuilder = ListPagesRequest.newBuilder();

      String parentPath =
          String.format(
              "projects/%s/locations/%s/agents/%s/flows/%s", projectId, location, agentId, flowId);
      listRequestBuilder.setParent(parentPath);
      listRequestBuilder.setLanguageCode("en");

      // Make API request to list all pages in the project
      for (Page element : client.listPages(listRequestBuilder.build()).iterateAll()) {
        System.out.println(element);
      }
    }
  }

Node.js

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

async function listPages(projectId, agentId, flowId, location) {
  const pagesClient = new PagesClient();
  const listPageRequest = {
    parent: `projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}`,
    languageCode: 'en',
  };

  const response = await pagesClient.listPages(listPageRequest);
  console.log(response);
}

Python

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

async def list_page(project_id, agent_id, flow_id, location):
    pages_client = PagesAsyncClient()

    request = ListPagesRequest()
    request.parent = (
        f"projects/{project_id}/locations/{location}/agents/{agent_id}/flows/{flow_id}"
    )

    request.language_code = "en"

    response = await pages_client.list_pages(request=request)
    return response

Seiten löschen

Wenn Sie eine Seite für Ihren Agent löschen möchten, rufen Sie die Methode delete vom Typ Page auf.

Wählen Sie ein Protokoll und eine Version für die Seitenreferenz aus:

Protokoll V3 V3beta1
REST Seitenressource Seitenressource
RPC Benutzeroberfläche der Seite Benutzeroberfläche der Seite
C++ PagesClient Nicht verfügbar
C# PagesClient Nicht verfügbar
Einfach loslegen (Go) PagesClient Nicht verfügbar
Java PagesClient PagesClient
Node.js PagesClient PagesClient
PHP Nicht verfügbar Nicht verfügbar
Python PagesClient PagesClient
Ruby Nicht verfügbar Nicht verfügbar

Java

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

import com.google.cloud.dialogflow.cx.v3.DeletePageRequest;
import com.google.cloud.dialogflow.cx.v3.DeletePageRequest.Builder;
import com.google.cloud.dialogflow.cx.v3.PagesClient;
import java.io.IOException;

public class DeletePage {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String agentId = "my-agent-id";
    String flowId = "my-flow-id";
    String pageId = "my-page-id";
    String location = "my-location";

    deletePage(projectId, agentId, flowId, pageId, location);
  }

  // DialogFlow API Delete Page Sample.
  // Deletes a page from the provided parameters
  public static void deletePage(
      String projectId, String agentId, String flowId, String pageId, String location)
      throws IOException {

    // Note: close() needs to be called on the PagesClient object to clean up resources
    // such as threads. In the example below, try-with-resources is used,
    // which automatically calls close().
    try (PagesClient client = PagesClient.create()) {
      Builder deleteRequestBuilder = DeletePageRequest.newBuilder();

      deleteRequestBuilder.setName(
          "projects/"
              + projectId
              + "/locations/"
              + location
              + "/agents/"
              + agentId
              + "/flows/"
              + flowId
              + "/pages/"
              + pageId);

      // Make API request to delete page
      client.deletePage(deleteRequestBuilder.build());
      System.out.println("Successfully deleted page!");
    }
  }

Node.js

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

async function deletePage(projectId, agentId, flowId, pageId, location) {
  const pagesClient = new PagesClient();

  const req = {
    name: `projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}/pages/${pageId}`,
  };

  const response = await pagesClient.deletePage(req);
  console.log(response);
}

Python

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Dialogflow zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

async def delete_page(project_id, agent_id, flow_id, page_id, location):
    pages_client = PagesAsyncClient()

    request = DeletePageRequest()
    request.name = f"projects/{project_id}/locations/{location}/agents/{agent_id}/flows/{flow_id}/pages/{page_id}"

    response = await pages_client.delete_page(request=request)
    return response