Actions-On-Google NodeJS v2 alpha:意图中能否多次调用conv.close()或传入多元素?
Great question! Let's clarify how conv.close() works in the v2 alpha version:
Can you call conv.close() multiple times in a single intent?
Nope, this won't work. Once you call conv.close() the first time, the conversation is marked as closed internally. Any subsequent calls to conv.close() in the same intent will be ignored—and might even throw unexpected errors, since the system expects the response flow to end after the first close.
Think of it like this: conv.close() is a one-way door. Once you walk through it, you can't go back to add more exit messages in the same intent.
Can you pass multiple elements in a single conv.close() call?
Absolutely! This is the supported way to send multiple exit elements. You can pass multiple response objects directly as arguments to conv.close(), or pass an array of these objects.
Here's a quick example:
// Pass multiple elements as separate arguments conv.close( new SimpleResponse({ speech: "Thanks for stopping by!", text: "Thanks for stopping by! Check out our help center if you need more info." }), new BasicCard({ title: "Help Center", text: "Find answers to all your questions here.", buttons: [new Button({ title: "Visit", url: "https://example.com/help" })] }) ); // Or pass an array of elements const exitElements = [ new SimpleResponse("See you later!"), new Image({ url: "https://example.com/goodbye.png", alt: "Goodbye image" }) ]; conv.close(exitElements);
Both approaches will send all the provided elements as part of the final exit response, just like how conv.ask() handles multiple elements in a single call.
内容的提问来源于stack exchange,提问作者user9518645

