Bot Framework - Facebook Prompt issue - facebook

I am using bot framework. I have my Facebook bot online and I am inspecting all the requests in my server. Sometimes my server is not receiving prompts answers (HeroCards buttons work perfect). If I retry and send a message many times, it works. If I use the emulator it works fine.
I wrote three times "pollo" to get the answer.
module.exports = (bot, builder, connector) => {
bot.dialog('/delivery', [
(session) => {
session.send('Bienvenido a 99UNO Delivery.');
let msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([
new builder.HeroCard(session)
.title('Pizza')
.subtitle('Todas nuestras pizzas.')
.images([
builder.CardImage.create(session, 'http://www.cateringolivia.com.ar/fotos/ser2_1g.jpg')
.tap(builder.CardAction.showImage(session, 'http://mx.cdn01.mundotkm.com/2016/01/e9a9d35c744f3ff11a97e32274411d8b_large.jpeg')),
])
.buttons([
builder.CardAction.imBack(session, 'Pizza', 'Seleccionar')
]),
new builder.HeroCard(session)
.title('Parrilla')
.subtitle('Carne, Pollo, Achuras.')
.images([
builder.CardImage.create(session, 'https://media-cdn.tripadvisor.com/media/photo-s/03/85/0c/c7/parrilla-tour-buenos.jpg')
.tap(builder.CardAction.showImage(session, 'https://restorando-res.cloudinary.com/image/upload/s--L2hhcZz2--/c_fit,f_auto,h_500,w_700/v1416341745/restaurant_photos/x/6939/52684/restaurante_parrilla-atahualpa_centro_10390894_1485980544972645_3906330496111888189_n.jpg')),
])
.buttons([
builder.CardAction.imBack(session, 'Parrilla', 'Seleccionar')
])
]);
builder.Prompts.choice(session, msg, 'Pizza|Parrilla', {listStyle: builder.ListStyle.button});
},
(session, results) => {
session.beginDialog('/' + results.response.entity.toLowerCase());
}
]);
bot.dialog('/pizza', [
(session) => {
builder.Prompts.choice(session, 'Qué gusto desea pedir?', 'mozzarella|napolitana|jamon', {listStyle: builder.ListStyle.button});
},
(session, results) => {
session.endDialog('Ya estamos llevando una pizza de ' + results.response.entity + ' a tu casa. Que lo disfrutes!');
}
]);
bot.dialog('/parrilla', [
(session) => {
builder.Prompts.choice(session, 'Qué desea pedir?', 'vacio|pollo', {listStyle: builder.ListStyle.button});
},
(session, results) => {
session.endDialog('Ya estamos llevando el ' + results.response.entity + ' a tu casa. Que lo disfrutes!');
}
]);
};
Server: Nodejs in Amazon ec2. Using morgan in index.js:
app.use(morgan(':method :url :status - [:date[clf]] - :remote-addr - :response-time'));
Any idea?

Related

How do I get carrier name and cell tower ID in Android 11 and above using IONIC?

We have developed app to show mobile internet speed using IONIC framework. We want to display the carrier name and cell tower ID. Everything is working fine till Android 10 but starting Android 11 onwards the data is not displayed. Any help to resolve this will be great.
our code looks as follows
hasReadPermission() {
this.sim.hasReadPermission().then(
(result) => {
console.log('hasReadPermission: ', result);
this.sim.getSimInfo().then(
(info) => {
this.simInfo = info.carrierName;
console.log(this.simInfo);
},
(err) => console.log('getSimInfo error: ', err);
);
},
(err) => {
console.log('Dont have permission: ', err)
this.requestReadPermission();
};
);
}
we not able to figure out where we went wrong

FBInstant.shareAsync( ) failed with 500

I'm doing the sharing in my instant game.
I'm firing next req from the game:
FBInstant.shareAsync(
{
intent: 'REQUEST',
image: 'image-encoded-here',
text: 'Edgar just played BASH for 9 points!',
data: { myReplayData: 'message sent' },
}
).then( function()
{
console.log("sharing is done");
})
.catch( function(err)
{
console.log('failed to share: ' + err.code + " :: " + err.message);
});
but I'm receiving 500-error:
https://www.facebook.com/games/quicksilver/share_score/?dpr=2 500 ()
failed to share: NETWORK_FAILURE ::
=====================================
in My particulare case problems was with encoded image.
As i remember, image to share should include all the encoded image stuff with "data:image/jpeg;base64,/" in front.
Look at your "image" parameter in the shareAsync(). You must send a Base64 url or it will go wrong.
Try removing the "," from the line
data: { myReplayData: 'message sent' },
data: { myReplayData: 'message sent' }

How to handle different languages with Google Actions and DiaglogflowApp with Firebase functions

I have configured multiple languages in my Dialogflow agent. I cannot figure out how to detect the language of the request in my firebase function in order to answer with the right language. Is there a standard approach to handle this? I don't see any function to detect the language in https://github.com/actions-on-google/actions-on-google-nodejs
I would expect to be able to do something like this:
const app = new DialogflowApp({request: request, response: response});
if (app.getLang == 'en') {
\\ Do something in english
}
else if (app.getLang == 'es') {
\\ Do something in spanish
}
There is a public sample on the AoG GitHub for Number Genie, which is in both French and English.
In this sample they define JSON objects for English and French locales:
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "cold genie",
"cardText": [
"Freezing like an ice cave in Antarctica?",
"I can't feel my face anymore",
"Hurry, before I turn into an icicle"
]
},
...
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "Génie froid",
"cardText": [
"Je me gèle comme un glaçon en Antartique",
"Je ne sens plus mon visage",
"Dépêchez-vous avant que je ne me transforme en glaçon"
]
},
...
Then there is a central strings.js file which will pull the correct string for that locale.
const i18n = require("i18n");
i18n.configure({
"directory": __dirname + "/locales",
"objectNotation": true,
"fallbacks": {
"fr-FR": "fr",
"fr-CA": "fr"
}
});
const prompts = () => ({
"welcome": {
"visual": {
"elements": [
[i18n.__("variants.greeting"), i18n.__("variants.invocation")],
i18n.__("variants.invocationGuess"),
i18n.__("images.intro")
],
"suggestions": onlyNumberSuggestions
}
},
...
Which is then used to map to each intent:
[Actions.GENERATE_ANSWER] () {
this.data.answer = strings.getRandomNumber(strings.numbers.min,
strings.numbers.max);
this.data.guessCount = 0;
this.data.fallbackCount = 0;
this.data.steamSoundCount = 0;
this.ask(strings.prompts.welcome, strings.numbers.min, strings.numbers.max);
}
The locale is set by getting that from the app.getUserLocale() method:
/**
* Get the Dialogflow intent and handle it using the appropriate method
*/
run () {
strings.setLocale(this.app.getUserLocale());
/** #type {*} */
const map = this;
const action = this.app.getIntent();
console.log(action);
if (!action) {
return this.app.ask(`I didn't hear a number. What's your guess?`);
}
map[action]();
}
There's definitely a lot here, and you don't need to do this exactly the same way. app.getUserLocale() should return the current locale, which you can then use in any way that you want to return the response.

How to read mail text in mail listener 2?

conf.js
var MailListener = require("mail-listener2");
var mailListener = new MailListener({
username: "*****#office365.com",
password: "******",
host: "outlook.office365.com",
port: 993, // imap port
tls: true,
fetchUnreadOnStart: true,
tlsOptions: {rejectUnauthorized: false},
mailbox: "INBOX",
searchFilter: "UNSEEN",
markSeen: true
});
mailListener.on("server:connected", function () {
console.log("imapConnected");
});
mailListener.on("server:disconnected", function () {
console.log("imapDisconnected");
});
(function () {
var count = 0;
mailListener.on("mail", function (mail, seqno, attributes) {
var mailuid = attributes.uid,
toMailbox = 'Inbox',
i = ++count;
if (i > 1) {
mailListener.stop(); // start listening
return;
}
console.log('email parsed', {
i: i,
subject: mail.subject,
from: mail.from,
text:mail.text,
seqno: seqno,
uid: attributes.uid,
attributes: attributes
});
expect(mail.subject).toEqual("FW: Secure One-Time-Password for Account Login");
var pattern = new RegExp(/Please use (\w+)/g);
var regCode = pattern.exec(mail.text)[1];
console.log(regCode);
console.log('attempting to mark msg read/seen');
mailListener.imap.addFlags(mailuid, '\\Seen', function (err) {
if (err) {
console.log('error marking message read/SEEN');
return;
}
//console.log('moving ' + (seqno || '?') + ' to ' + toMailbox);
//mailListener.imap.move(mailuid, toMailbox, function (err) {
if (err) {
console.log('error moving message');
return;
}
console.log('moved ' + (seqno || '?'), mail.subject);
});
});
});
})
();
mailListener.start(); // start listening
setTimeout(function () {
mailListener.stop(); // start listening
}, 60 * 1000);
I am reading all the details except text and the text is in html table format.
Instead of text i am getting undefined message.If needed i will add html code also.
If i am forwarding the same mail to gmail from office 365 and reading the mail from gmail i am able to get text.
Error:
subject: 'test mail',
from: [ { address: 'otp#gmail.com', name: 'gmail.com' } ],
body: undefined,
seqno: 2,
uid: 18,
attributes:
{ date: 2017-06-14T16:22:06.000Z,
flags: [ '\\Seen' ],
uid: 18,
modseq: '3914',
'x-gm-labels': [],
'x-gm-msgid': '1570197813730673685',
'x-gm-thrid': '1570197813730673685' } }
[21:56:13] E/launcher - Cannot read property '1' of null
[21:56:13] E/launcher - TypeError: Cannot read property '1' of null
I see that this is an old issue, but I am facing the same problem and using the nearly the same function.
I want to get the content of the e-mail with a link and the email is in HTML. So: mail.text doesn't and won't work in this case.
Solution is really simple and it works for me straight forward: mail.html

Strophe addHandler doesn't work

This is a relevant question to "Strophe.Connection.addHandler no works if call Strophe.Connection.sendIQ" but it doesn 't help me. I am trying to run a program of the book "Wrox Professional XMPP Programming with JavaScript and jQuery Book" which is a collaborative editor.
$(document).bind('connected', function () {
$('#disconnect').removeAttr('disabled');
NetPad.connection.addHandler(NetPad.on_message, null, "message");
if (NetPad.collaborator) {
NetPad.master = false;
$('#status')
.text('Checking feature support for ' + NetPad.collaborator + '.')
.attr('class', 'try-collab');
// check for feature support
NetPad.connection.sendIQ(
$iq({to: NetPad.collaborator, type: 'get'})
.c('query', {xmlns: Strophe.NS.DISCO_INFO}),
function (iq) {
console.log(iq);
var f = $(iq).find(
'feature[var="' + NetPad.NS_NETPAD + '"]');
if (f.length > 0) {
$('#status')
.text('Establishing session with ' +
NetPad.collaborator + '.')
.attr('class', 'try-collab');
NetPad.connection.send(
$pres({to: NetPad.collaborator})
.c('collaborate', {xmlns: NetPad.NS_NETPAD}));
} else {
$('#status')
.text('Collaboration not supported with ' +
NetPad.collaborator + '.')
.attr('class', 'no-collab');
NetPad.connection.disconnect();
}
});
} else {
NetPad.master = true;
$('#pad').removeAttr('disabled');
// handle incoming discovery and collaboration requests
**NetPad.connection.addHandler(NetPad.on_disco_info,
Strophe.NS.DISCO_INFO, "iq", "get");**
NetPad.connection.addHandler(NetPad.on_collaborate,
NetPad.NS_NETPAD, "presence");
NetPad.connection.addHandler(NetPad.on_unavailable,
null, "presence");
}
});
on_disco_info: function (iq) {
console.log("==> On_disco_info()...");
NetPad.connection.sendIQ(
$iq({to: $(iq).attr('from'),
id: $(iq).attr('id'),
type: "result"})
.c('query', {xmlns: Strophe.NS.DISCO_INFO})
.c('identity', {category: 'client',
type: 'pc'}).up()
.c('feature', {'var': NetPad.NS_NETPAD}));
return true;
},
The problem is that NetPad.on_disco_info(iq), isn't fired when a connection with another colloborator is made, though an iq stanza is sended. I omitted the rest of the addHandler's arguments, to get all iq but again nothing.
My server is ejabberd.
Please ask if something is not understandable.