当前位置: 首页>>代码示例>>Java>>正文


Java Session类代码示例

本文整理汇总了Java中com.amazon.speech.speechlet.Session的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Session类属于com.amazon.speech.speechlet包,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Namespace, NamespaceList, ?, ?>> ctx = createContext(request.getIntent(), session);
    LOGGER.info("Listing all namespaces.");

    try {
        List<String> namespaces = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (namespaces.isEmpty()) {
            return newResponse("No namespaces found.");
        } else {
            return newResponse("The available namespaces are: " + join(namespaces, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:21,代码来源:GetNamespaces.java

示例2: handleProgress

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
private SpeechletResponse handleProgress(IntentRequest request, Session session) {
  checkCalendarName(request, session);

  if(allSlotsFilled(request)) {
    final String title = collectSummary(request);
    final DateTime from = DateTime.parse(
        sv(request, SLOT_DATE_FROM) + "T" + sv(request, SLOT_TIME_FROM));
    final DateTime to = getTimeTo(request, from);

    final String dateFormat = messageService.de("event.new.card.content.time.format");
    session.setAttribute(SESSION_DATE_FORMAT, dateFormat);
    session.setAttribute(SESSION_FROM, from.toString(dateFormat));
    session.setAttribute(SESSION_TO, to.toString(dateFormat));

    final OutputSpeech speech = speechService.confirmNewEvent(title, from, to, request.getLocale());
    return SpeechletResponse.newDialogConfirmIntentResponse(speech);
  }

  //normally we want to delegate because we have defined the dialog into the model on alexa
  if( request.getDialogState() != DialogState.COMPLETED) {
    Intent updatedIntent = updateIntent(request.getIntent());
    return SpeechletResponse.newDialogDelegateResponse(updatedIntent);
  }

  return SpeechletResponse.newTellResponse(speechService.speechCancelNewEvent(request.getLocale()));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:27,代码来源:NewEventSpeechlet.java

示例3: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    if (!getKubernetesClient().isAdaptable(OpenShiftClient.class)) {
        return newFailureNotice("Your cluster is not Openshift!");
    }

    IntentContext<BaseOperation<DeploymentConfig, DeploymentConfigList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all deployment configs for namespace:" + namespace);

    try {
        List<String> deployments = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (deployments.isEmpty()) {
            return newResponse("No deployment configs found.");
        } else {
            return newResponse("The available deployment configs are: " + join(deployments, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:26,代码来源:GetDeploymentConfigs.java

示例4: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all failing pods for namespace:" + namespace);

    try {
        List<String> pods = list(ctx)
                .getItems()
                .stream()
                .filter(p -> FAILED_PHASE.equalsIgnoreCase(p.getStatus().getPhase()))
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (pods.isEmpty()) {
            return newResponse("No failing pods found in namespace " + namespace);
        } else {
            return newResponse("The failing pods in namespace " + namespace + " are: " + join(pods, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:23,代码来源:GetFailingPods.java

示例5: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Deployment, DeploymentList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all deployments for namespace:" + namespace);

    try {
        List<String> deployments = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (deployments.isEmpty()) {
            return newResponse("No deployments found.");
        } else {
            return newResponse("The available deployments are: " + join(deployments, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetDeployments.java

示例6: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all pods for namespace:" + namespace);

    try {
        List<String> pods = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (pods.isEmpty()) {
            return newResponse("No pods found in namespace " + namespace);
        } else {
            return newResponse("The available pods in namespace " + namespace + " are: " + join(pods, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetPods.java

示例7: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Namespace, NamespaceList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, null);
    if (Utils.isNullOrEmpty(namespace)) {
        throw new IllegalStateException("Namespace needs to be specified either via intent slots, or via session attributes.");
    }
    try {
        LOGGER.info("Create namespace:" + namespace);

        newOperation().create(new NamespaceBuilder()
                .withNewMetadata()
                .withName(namespace)
                .endMetadata()
                .build());


        return newResponse("Successfully created namespace " + namespace);
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:23,代码来源:CreateNamespace.java

示例8: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Service, ServiceList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all services for namespace:" + namespace);

    try {
        List<String> services = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (services.isEmpty()) {
            return newResponse("No services found in namespace " + namespace);
        } else {
            return newResponse("The available services in namespace " + namespace + " are: " + join(services, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetServices.java

示例9: onRequest

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    if (!getKubernetesClient().isAdaptable(OpenShiftClient.class)) {
        return newFailureNotice("Your cluster is not Openshift!");
    }

    IntentContext<BaseOperation<Project, ProjectList, ?, ?>> ctx = createContext(request.getIntent(), session);
    LOGGER.info("Listing all projects.");

    try {
        List<String> projects = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (projects.isEmpty()) {
            return newResponse("No projects found.");
        } else {
            return newResponse("The available projects are: " + join(projects, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:25,代码来源:GetProjects.java

示例10: getVariable

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
private static final String getVariable(String key, Intent intent, Session session, String fallbackValue) {
    LOGGER.debug("Getting variable: [" + key + "], from slots:["
            + join(intent.getSlots().keySet(), " ")
            + "] and session: ["
            + join(session.getAttributes().keySet(), " ") + "].");

    String result = null;
    if (intent.getSlots().containsKey(key)) {
        result = intent.getSlot(key).getValue();
    } else if (session.getAttributes().containsKey(key)) {
        result = String.valueOf(session.getAttribute(key));
    }

    if (Utils.isNullOrEmpty(result)) {
        result = fallbackValue;
    }
    return result;
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:19,代码来源:IntentContext.java

示例11: onIntent

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
public SpeechletResponse onIntent(IntentRequest request, Session session) throws SpeechletException {
    LOGGER.info("onRequest requestId={}, sessionId={}", request.getRequestId(), session.getSessionId());
    // Get intent from the request object.
    Intent intent = request.getIntent();
    String intentName = (intent != null) ? intent.getName() : null;

    RequestHandlerFactory factory = GetRequestHandlerFactory.FUNCTION.apply(intentName);

    if (factory != null) {
        return factory.create(context).onRequest(request, session);
    } else {
        return new SpeechletResponseBuilder()
                .withNewPlainTextOutputSpeechOutputSpeech()
                    .withText("I don't know how to do that.")
                .endPlainTextOutputSpeechOutputSpeech()
                .build();
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:19,代码来源:RequestDispatcher.java

示例12: handleDialogAction

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@OnIntent("NewEvent")
public SpeechletResponse handleDialogAction(final IntentRequest request, final Session session) throws CalendarWriteException {
  session.setAttribute(BasicSpeechlet.KEY_DIALOG_TYPE, BasicSpeechlet.DIALOG_TYPE_NEW_EVENT);
  final SpeechletResponse response;

  try {
    switch (request.getIntent().getConfirmationStatus()) {
      default:
      case NONE: response = handleProgress(request, session);
        break;
      case CONFIRMED: response = handleConfirmed(request, session);
        break;
      case DENIED: response = handleDenied(request, session);
        break;
    }
  } catch (CalendarWriteException e) {
    return SpeechletResponse.newTellResponse(speechService.speechError(e));
  }

  response.setShouldEndSession(false);
  return response;
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:23,代码来源:NewEventSpeechlet.java

示例13: handleConfirmed

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
private SpeechletResponse handleConfirmed(IntentRequest request, Session session)
    throws CalendarWriteException {
  final String dateFormat = session.getAttribute(SESSION_DATE_FORMAT).toString();
  final DateTimeFormatter parser = DateTimeFormat.forPattern(dateFormat);
  final String title = collectSummary(request);
  final String calendar = session.getAttribute(SESSION_CALENDAR) != null ? session.getAttribute(SESSION_CALENDAR).toString() : null;
  final String from = session.getAttribute(SESSION_FROM).toString();
  final String to = session.getAttribute(SESSION_TO).toString();

  calendarService.createEvent(calendar, title,
      parser.parseDateTime(from),
      parser.parseDateTime(to));

  SimpleCard card = new SimpleCard();
  card.setTitle(messageService.de("event.new.card.title"));
  card.setContent(messageService.de("event.new.card.content", title, from, to));

  session.removeAttribute(BasicSpeechlet.KEY_DIALOG_TYPE);

  return SpeechletResponse.newTellResponse(
      speechService.speechNewEventSaved(request.getLocale()),
      card);
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:24,代码来源:NewEventSpeechlet.java

示例14: inProgress_NotAllSlotsAreFilled

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
@Test
public void inProgress_NotAllSlotsAreFilled() throws CalendarWriteException {
  //given
  final Session session = Session.builder()
      .withSessionId("<session-id>")
      .build();
  final Intent intent = Intent.builder()
      .withName("<intent>")
      .withSlots(slots(
        slot("day", null)
      ))
      .build();
  final IntentRequest request = IntentRequest.builder()
      .withRequestId("<requestId>")
      .withIntent(intent)
      .withDialogState(DialogState.IN_PROGRESS)
      .build();

  //when
  final SpeechletResponse response = toTest.handleDialogAction(request, session);

  //then
  assertEquals(
      json(SpeechletResponse.newDialogDelegateResponse(intent)),
      json(response));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:27,代码来源:NewEventSpeechletTest.java

示例15: checkCalendarName

import com.amazon.speech.speechlet.Session; //导入依赖的package包/类
private void checkCalendarName(final String calendarSlot, final String expectedCalendar) throws CalendarWriteException {
  final Intent intent = Intent.builder()
      .withName("<intent>")
      .withSlots(slots(
          slot("calendar", calendarSlot)
      ))
      .build();
  final IntentRequest request = IntentRequest.builder()
      .withRequestId("<requestId>")
      .withIntent(intent)
      .withDialogState(DialogState.IN_PROGRESS)
      .build();
  final Session session = Session.builder()
      .withSessionId("<sessionId>")
      .build();
  doReturn(new HashSet<>(Arrays.asList("Geburtstage", "Termine", "Haushalt"))).when(toTest).getCalendarNames();

  toTest.handleDialogAction(request, session);

  //then
  assertEquals(expectedCalendar, session.getAttribute(SESSION_CALENDAR));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:23,代码来源:NewEventSpeechletTest.java


注:本文中的com.amazon.speech.speechlet.Session类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。