Ошибка запуска облака: не удалось запустить контейнер. Не удалось запустить, а затем прослушать порт, определенный переменной среды PORT - PullRequest
0 голосов
/ 16 апреля 2020

Я пытаюсь интегрировать Whatsapp Chatbot, используя Cloud, и получаю эту ошибку при попытке развертывания. Я новичок в этой части кодирования, поэтому любая помощь будет оценена.

Я перешел по этой ссылке: https://github.com/GoogleCloudPlatform/dialogflow-integrations/tree/03676af04840c21c12e2590393d5542602591bee

/**
 * Copyright 2019 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
const express = require('express');
const request = require('request');
const app = express();
const dialogflowSessionClient =
    require('../botlib/dialogflow_session_client.js');
const bodyParser = require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

//For authenticating dialogflow_session_client.js, create a Service Account and
// download its key file. Set the environmental variable
// GOOGLE_APPLICATION_CREDENTIALS to the key file's location.
//See https://dialogflow.com/docs/reference/v2-auth-setup and
// https://cloud.google.com/dialogflow/docs/setup for details.

const projectId ='chennai-against-corona-vgomsd';
const phoneNumber ="+15404183625";
const accountSid = 'AC6c60eee5e7bbd7476d8becd46c200d50';
const authToken = '9174e1426fd6635473fb671d4f0b10f4';

const client = require('twilio')(accountSid, authToken);
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const sessionClient = new dialogflowSessionClient(projectId);

const listener = app.listen(process.env.PORT, function() {
  console.log('Your Twilio integration server is listening on port '
      + listener.address().port);
});
app.post('/', async function(req, res) {
  const body = req.body;
  const text = body.Body;
  const id = body.From;
  const dialogflowResponse = (await sessionClient.detectIntent(
      text, id, body)).fulfillmentText;
  const twiml = new  MessagingResponse();
  const message = twiml.message(dialogflowResponse);
  res.send(twiml.toString());
});

process.on('SIGTERM', () => {
  listener.close(() => {
    console.log('Closing http server.');
    process.exit(0);
  });
});

1 Ответ

0 голосов
/ 17 апреля 2020

Ошибка, с которой вы сталкиваетесь, может быть связана с тем, что вы не прослушиваете входящие HTTP-запросы или прослушиваете входящие запросы на неправильном порту.

Вы можете увидеть в Официальная документация по Cloud Run , вы должны указать, что ваш контейнер должен прослушивать входящие HTTP-запросы на порт, определенный Cloud Run и предоставленный в переменной среды $PORT.

И если ваш контейнер не может выполнить прослушивать ожидаемый порт, проверка работоспособности ревизии завершится неудачно, и ревизия будет в состоянии ошибки, блокирующем трафик c, перенаправленный на него.

В Node.js вы можете использовать следующий код:

const port = process.env.PORT || 8080;
app.listen(port, () => {
  console.log('Hello world listening on port', port);
});

Пожалуйста, дайте мне знать, если это решит вашу проблему.

...