How to make a multiple language Dialogflow webhook/fulfillment? - node.js

I have built a Dialogflow app in english. I used a NodeJs webhook to provide the answers.
Now, I want to add a new language (Spanish). Is there a way to add it without duplicating the webhook?
Is there a prebuilt Library ,like I18N, where I provide the translation and depending on the "languageCode": "en", I send the answer?

The general solution is for you to use a localization library of your choice, send it a string identifier, and send the response that it generates. There are several libraries that Google suggests, however you should be able to use whichever one works best for you. There are some issues using i18n-node if you are using asynchronous code - the problems and solutions are also discussed by the team.
There is also the multivocal library, which takes a different approach to generating responses, but has localization built-in.

Related

Webhook and javascript for DialogFlow, where do I find documentation?

I'm trying to learn DialogFlow (Google assistant) and I'm not so experienced in Javascript. I'm looking at various examples like Build Actions for the Google Assistant Level 2, 3 e.t.c.
But it's like you're supposed to know already how the javscript side of things (the code deployed to Firebase, Node.js) works. I've found the API reference but it's very extensive. I just want to look up things from the Javascript code examples – say, like a description of the method .intentin the dialogFlow object and which other methods there are in this class. But I've no idea where to find things like this. When I search I end up in the wrong places.
Part of what the issue may be is that you're mixing up two different, but related, technologies. Actions on Google are the tools for building for the Google Assistant. It can use Dialogflow as its Natural Language Processing system, and most people do, but it doesn't have to. Similarly, Dialogflow supports the Google Assistant as one of its platforms, but it also supports other platforms.
Adding to this confusion is that each has their own library that is targeted for their specific needs. The codelabs that you pointed to use the "actions-on-google" library, while the documentation link you pointed to goes to the "dialogflow" library.
Documentation for Conversational Actions can be found at https://developers.google.com/assistant/conversational/overview. Under the reference page there, you'll find a link to the documentation for the library (and rather than following this link, you should go to the developers page, since this links to a specific version of the library). You may find this documentation difficult to read, since it has classes that aren't relevant to you, but are there to abstract away differences between different version of the Actions on Google and Dialogflow protocols.
That documentation, however, can be a little difficult to read. It doesn't make clear, for example, that the typical lines to setup the application
const {dialogflow} = require('actions-on-google');
const app = dialogflow({debug: true});
are creating an instance of a DialogflowApp. Or that the object that is passed to your handler and typically named "conv":
app.intent('Default Welcome Intent', (conv) => {
// Do things
});
is an instance of DialogflowConversation.

How do we can send APIs to DialogFlow in any language?

As right now i have some problems regarding APIs query for language. I knew that Cambodian language is not support in DialogFlow and when i wrote in DialgFlow in test within DialogFlow , it works fine but when i'm trying to send through APIs it's not work because resolve query going to be unreadable code. Is there any possible way that we can send it through APIs in another language that is not yet support?
Thanks
When you say Cambodian language, do you mean Khmer? Google Cloud's Translate API (https://cloud.google.com/translate/) supports Khmer, which could help with this.
As far as Dialogflow is concerned, these pages of documentation should help with fulfillment:
https://dialogflow.com/docs/reference/language
https://dialogflow.com/docs/agents/multilingual

Which is better to use for Google Assistant? Actions SDK or JSON request response

I have built multiple actions on Google Assistant using the JSON request and response V2 but I have heard that using Actions SDK for building actions specifically for Google Assistant should be preferred. I am confused whether to use Actions SDK or JSON request response?
For example - On this link, for every sample code there are two tabs, Node.js using Actions SDK and JSON using the JSON request response.
Which one should be preferred and in which scenarios?
Thanks!
Let's first look at what those tabs mean, and then discuss what your best approach should be.
node.js vs JSON tabs
The "node.js" tab shows what the code looks like using the actions-on-google library. For the most part, this library uses the same code if you're using either the Action SDK or using Dialogflow to implement. Where there are differences, the documentation does note how you have to handle them - this is particularly true when it comes to how you have to handle responses.
The "JSON" tab shows what the JSON would look like if you are not using the actions-on-google library and need to send JSON yourself. You might do this because you're using a language besides node.js, or you just want to know what the underlying protocol looks like.
The catch is that the JSON illustrated here is what would be used by the Action on Google JSON protocol. If you're using Dialogflow, then this JSON would be wrapped inside the payload.google field and there are a couple of other differences documented. So when generating JSON for a Dialogflow response, you should use this as a guide, but need to be aware of how it might differ.
What should you use?
What you use depends on what your needs are and what your goals are for developing.
If you are trying to develop something you intend to release, or might do so someday, and you are new to voice or bot interfaces, then you'll probably want to use Dialogflow - no matter what other choices you may make.
If you have your own Natural Language Processing (NLP) system, then you will want to use the Action SDK instead of Dialogflow. How you handle it (using the actions-on-google library or using JSON) will depend on how you need to integrate with that NLP.
If you're familiar with node.js, or want to learn it, then using the actions-on-google library is a good choice and that first tab will help you. (There are other choices. Dialogflow also has a dialogflow-fulfillment library, which is good if you want to be able to support the bot platforms it supports as well. The multivocal library has a more configuration-driven template approach to building a conversational backend that was designed to work with the Assistant and Dialogflow. Both of these illustrate how to do the same things that Google's documentation does.)
If you would rather use another language, you'll need to reference the JSON documentation because there are few complete libraries for these platforms. Your best bet would be to use Dialogflow with JSON. Dialogflow has some example JSON for how to apply the Google documentation you cite to their fulfillment protocol.
Summary
You should probably use Dialogflow.
If you can, use actions-on-google or another library.
If you have a need to use another language or want to use the JSON, be aware of the possible differences.

SendGrid-nodejs or Nodemailer?

There are at least two ways to send email from Nodejs using SendGrid:
Sendgrid provides a Nodejs library called "SendGrid-nodejs." They're actively supporting Sendgrid-Nodejs (last update 29 days ago).
Nodemailer supports sendgrid and seems to be extremely popular. SendGrid posted an article about using this combination: Sending email with Nodemailer and Sendgrid.
Edit 2
SendGrid have ended support for nodemailer-sendgrid-transport as of today.
So, if you're starting on a project now, I would suggest going with sendgrid-nodejs.
Original question:
Edit to make the question less opinion-based:
What are the pros and cons to each approach? I have googled for days and not seen any comparison of the two. There is another StackOverflow question asking for differentiation between the two (among several other things) which has gone unanswered. So surely the answer to this will help others.
My specific usage, in case it helps focus the answers:
I want to allow users of an iPhone app to invite others to use the app. They'll see the default invitation text in the app, and can customize it. The customized text is sent to my Nodejs server and added to a job queue. As the queue is processed, emails are sent. I want the emails to look nice, so I want to use HTML email templates (and a plaintext alternate body).
Scale-wise, this will start out very small but if the app is succssful could scale up rapidly.
You'll find that you can achieve what you want to do using either library (nodemailer-sendgrid-transport was written by SendGrid too!) but given you suggest that you want to use HTML templates and plain text alternatives, you might want to take a look at using the SendGrid Node JS library because it'll give you easier access to some more advanced features, such as:
Template Engine - Which allows you to manage both HTML and plain text templates inside the SG dashboard rather than in your code - this could be handy for making quick changes, without the need to redeploy your app to production.
Advanced Suppression Management - Which allows you to group emails that users can then unsubscribe from, rather than completely unsubscribing from everything, ever.
It's worth noting that you could still use both these features with NodeMailer and nodemailer-sendgrid-transport, but the SendGrid NodeJS library directly exposes methods for these features.
Like I said, you can achieve what you want with either but I thought it was worth pointing out a few SendGrid specific things.
Well, sendgrid-nodejs is a more popular repository.
However, Nodemailer is the most popular module for sending emails with NodeJS. I've been using it for months and I'm very satisfied.
If you're worried about the future of your app you should consider that Nodemailer is used not just with Sendgrid, but with a lot of other competitors. So if you have a problem with Sendgrid, you could easily switch to another email delivery service without having to learn a different API.
So I suggest you to use nodemailer-sendgrid-transport, and if you find bugs, fix them with a PR :P

How can i use ASIHTTP Request in My Project?

Hi I want to Implement ASIHTTP Request in my Project so how can i implement it and how it is good compare to NSURLRequest?
There are extensive descriptions on ASIHTTPRequest setup and usage on project site. Read it carefully and if you still have any specific questions after that ask them.
Note that ASIHTTPRequest does not include any parsing frameworks so to parse server response you'll need another libs
http://allseeing-i.com/ASIHTTPRequest/How-to-use#downloading_the_response_directly_to_a_file

Resources