async function searchHotel()

in lex-validate-lambda/searchHotel/CodeHookHandler.js [74:166]


async function searchHotel(request, customerName, customerPhoneNumber, city) {
  const response = await graphqlClient.query({
    query: ByCustomerName,
    variables: {
      customerName: customerName.value.interpretedValue.replace(/(\s*)/g, ""),
    },
  });
  console.log(
    "response.data.ByCustomerName.items=",
    response.data.ByCustomerName.items
  );

  let hotelName;
  let customerNameItems = response.data.ByCustomerName.items;
  let sessionAttributes = request.sessionAttributes || {};

  if (customerNameItems && customerNameItems.length > 1) {
    console.log("size is over than 1");

    for (let i = 0; i < customerNameItems.length; ++i) {
      console.log("id == ", customerNameItems[i]);

      if (
        customerNameItems[i].customerPhoneNumber ===
        customerPhoneNumber.value.interpretedValue.replace(/(\s*)/g, "")
      ) {
        if (
          customerNameItems[i].city &&
          customerNameItems[i].city ===
            city.value.interpretedValue.replace(/(\s*)/g, "")
        ) {
          hotelName = customerNameItems[i].hotelName;
          console.log("hotelName == ", hotelName);
          return closeResponse(
            sessionAttributes,
            "Fulfilled",
            request.interpretations[0].intent.name,
            i18n.t("closeResponse", {
              customerName: customerName.value.interpretedValue,
              hotelName: hotelName,
            })
            // `${customerName.value.interpretedValue} 님께서 예약하신 호텔은 ${hotelName}입니다`
          );
        } else {
          console.log("hotelName  else");

          return elicitIntentResponse(
            sessionAttributes,
            i18n.t("elicitIntentResponse", {
              city: city.value.interpretedValue,
            })
            //  `${city.value.interpretedValue} 에 예약된 호텔이 없습니다. 다시 예약을 원하시면 "호텔예약 다시해죠" 라고 말씀해주세요 `
          );
        }

        break;
      }
    }
  } else {
    if (
      customerNameItems[0].city &&
      customerNameItems[0].city ===
        city.value.interpretedValue.replace(/(\s*)/g, "")
    ) {
      hotelName = customerNameItems[0].hotelName;
      console.log("hotelName == ", hotelName);
    } else {
      console.log("hotelName  else");

      return elicitIntentResponse(
        sessionAttributes,
        i18n.t("elicitIntentResponse", {
          city: city.value.interpretedValue,
        })
        // `${customerName.value.interpretedValue.replace(
        //   /(\s*)/g,
        //   ""
        // )} 에 예약된 호텔이 없습니다. 다시 예약을 원하시면 "호텔예약 다시해죠" 라고 말씀해주세요 `
      );
    }
  }
  console.log("-  hotelName = ", hotelName);
  return closeResponse(
    sessionAttributes,
    "Fulfilled",
    request.interpretations[0].intent.name,
    i18n.t("closeResponse", {
      customerName: customerName.value.interpretedValue,
      hotelName: hotelName,
    })
    //   `${customerName.value.interpretedValue} 님께서 예약하신 호텔은 ${hotelName}입니다`
  );
}