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


Java User类代码示例

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


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

示例1: createParticipant

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
protected Participant createParticipant(final SpeechletRequestEnvelope<IntentRequest> requestEnvelope,
		final User user) {
	final Participant result = new Participant();
	result.setPlatform(AlexaPlatformEnum.ALEXA);
	result.setId(user.getUserId());

	if (requestEnvelope == null) {
	} else if (requestEnvelope.getContext() == null) {
	} else {
		final Context context = requestEnvelope.getContext();
		final SystemState state = context.getState(SystemInterface.class, SystemInterface.STATE_TYPE);

		if (state == null) {
		} else if (state.getDevice() == null) {
		} else {
			final Device device = state.getDevice();
			final String deviceId = device.getDeviceId();
			result.setDeviceId(deviceId);
		}
	}

	return result;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:24,代码来源:AlexaReceiveMessageFactoryImpl.java

示例2: createReceiveMessage

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
@Override
public ReceiveMessage createReceiveMessage(final IntentRequest intentRequest, final User user,
		final SpeechletRequestEnvelope<IntentRequest> requestEnvelope, final Map<String, String[]> params) {
	final ReceiveMessage result = new ReceiveMessage();
	result.setMessageId(intentRequest.getRequestId());

	final Participant sender = createParticipant(requestEnvelope, user);
	result.setSender(sender);

	final Participant recipient = createParticipant(requestEnvelope, user);
	result.setRecipient(recipient);

	if (params != null) {
		result.getParams().putAll(params);
	}

	final TextReceivePayload payload = createTextReceivePayload(intentRequest);
	result.addPayload(payload);
	return result;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:21,代码来源:AlexaReceiveMessageFactoryImpl.java

示例3: onIntent

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
protected SpeechletResponse onIntent(final SpeechletRequestEnvelope<IntentRequest> requestEnvelope,
		final IntentRequest request) {
	final SpeechletResponse result;
	final User user = requestEnvelope.getSession().getUser();

	receiveMessage(request, user, requestEnvelope);

	final String text = alexaMessageSender.getText();

	final SsmlOutputSpeech speech = new SsmlOutputSpeech();
	final String wrappedSsmlText = wrapTextForSsml(text);
	speech.setSsml(wrappedSsmlText);

	final Card card = alexaMessageSender.getCard();

	if (card == null) {
		result = SpeechletResponse.newTellResponse(speech);
	} else {
		result = SpeechletResponse.newTellResponse(speech, card);
	}

	result.setNullableShouldEndSession(alexaMessageSender.getShouldEndSession());

	return result;
}
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:26,代码来源:Bot4jSpeechletImpl.java

示例4: createSession

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
@Before
public void createSession() {
    final Application application = new Application("applicationId");
    final User user = User.builder().withUserId("userId").withAccessToken("accessToken").build();
    session = Session.builder().withSessionId("sessionId")
            .withApplication(application).withUser(user).build();
    session.setAttribute(attributeKey, "value");
}
 
开发者ID:KayLerch,项目名称:alexa-skills-kit-states-java,代码行数:9,代码来源:AlexaStateModelTest.java

示例5: createSession

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
@BeforeClass
public static void createSession() {
    final Application application = new Application("test-" + UUID.randomUUID().toString());
    final User user = User.builder().withUserId("test-" + UUID.randomUUID().toString()).withAccessToken("test-" + UUID.randomUUID().toString()).build();
    session = Session.builder().withSessionId("test-" + UUID.randomUUID().toString())
            .withApplication(application).withUser(user).build();
}
 
开发者ID:KayLerch,项目名称:alexa-skills-kit-states-java,代码行数:8,代码来源:AlexaStateHandlerTest.java

示例6: createReceiveMessage

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
ReceiveMessage createReceiveMessage(final IntentRequest intentRequest, final User user,
final SpeechletRequestEnvelope<IntentRequest> requestEnvelope, Map<String, String[]> params);
 
开发者ID:nitroventures,项目名称:bot4j,代码行数:3,代码来源:AlexaReceiveMessageFactory.java

示例7: buildRequest

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
private HttpEntity<String> buildRequest(String intentName, Entry<String, Object>[] sAttributes, String[] rawSlots) {
  final HttpHeaders headers = new HttpHeaders();
  headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString());

  Session session = Session.builder()
      .withUser(new User("<user-id>"))
      .withApplication(new Application("<application-id>"))
      .withSessionId("<session-id>")
      .withAttributes(Stream.of(sAttributes).collect(Collectors.toMap(s -> s.getKey(), s -> s.getValue())))
      .withIsNew(true)
      .build();

  Map<String, Slot> slots = new HashMap<>();
  for(int i=0; i < rawSlots.length; i += 2) {
    String key = rawSlots[i];
    String value = rawSlots[i+1];

    slots.put(key, Slot.builder().withName(key).withValue(value).build());
  }

  Intent intent = Intent.builder()
      .withName(intentName)
      .withSlots(slots)
      .build();

  SpeechletRequest request = IntentRequest.builder()
      .withRequestId("<request-id>")
      .withTimestamp(DateTime.now().toDate())
      .withLocale(Locale.GERMANY)
      .withIntent(intent)
      .build();

  SpeechletRequestEnvelope body = SpeechletRequestEnvelope.builder()
      .withVersion("1.0")
      .withSession(session)
      .withRequest(request)
      .build();

  try {
    return new HttpEntity<>(mapper.writeValueAsString(body), headers);
  } catch (JsonProcessingException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:45,代码来源:CalendarSpeechletIT.java

示例8: doIntent

import com.amazon.speech.speechlet.User; //导入依赖的package包/类
@Override
public SpeechletResponse doIntent(@NonNull final Session session) {
    String speechText = "The the hottest five posts on Reddit are ";

    User sessionUser = session.getUser();

    HttpGet getReq = new HttpGet("https://oauth.reddit.com/hot.json");
    getReq.setHeader("Authorization","Bearer " + sessionUser.getAccessToken());

    CloseableHttpClient client = HttpClients.custom().setUserAgent("com.wintertonsmith.snoolexa 0.1.0-SNAPSHOT").build();

    //TODO: Either build or use an API wrapper for Reddit
    try {
        HttpResponse r = client.execute(getReq);

        String entity = EntityUtils.toString(r.getEntity());

        JsonParser parser =  new JsonParser();
        JsonObject rootObj = parser.parse(entity).getAsJsonObject();
        JsonArray posts = rootObj.get("data").getAsJsonObject().get("children").getAsJsonArray();

        //TODO: Allow for post by post reading and user reprompts for manipulation/paging
        for(int i = 0; i < ((posts.size() > 5) ? 5 : posts.size()); ++i) {

            //TODO: Build a POJO representation of the JSON data
            JsonObject postData = posts.get(i).getAsJsonObject().get("data").getAsJsonObject();

            JsonElement media = postData.get("media");
            String type = "self";
            if (media != null && !media.isJsonNull()) {
                JsonElement oembed = media.getAsJsonObject().get("oembed");
                if (oembed != null && !oembed.isJsonNull()) {
                    type = oembed.getAsJsonObject().get("type").getAsString();
                    if ("image".equals(type)) {
                        type = "an " + type;
                    } else {
                        type = "a " + type;
                    }
                }
            }

            String title = postData.get("title").getAsString();
            String subreddit = postData.get("subreddit").getAsString();
            speechText += type + " post with the title, " + title + " on r/" + subreddit + ".";

            if (i != posts.size() || i != 5) {
                speechText += " A ";
            }

        }

        speechText += " Those are the top 5 posts on Reddit. Goodbye!";

    } catch (IOException e) {
        log.error("Hot API req failed with IOException!", e);
    } finally {
        try {
            client.close();
        } catch (IOException ioe) {
            log.error("Failed to close the HTTP client stream.", ioe);
        }
    }

    SimpleCard card = new SimpleCard();
    card.setTitle("Snoolexa");
    card.setContent(speechText);

    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);



    return SpeechletResponse.newTellResponse(speech, card);
}
 
开发者ID:winterton,项目名称:snoolexa,代码行数:76,代码来源:HotPostsIntent.java


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