Mám dotaz ohledně nakládání s bohatými zpráv na facebooku.
Když se snažím odesílat zprávy s api.ai,
I odeslat zprávu jako vstoupit popis link zde
function MessageHandler(event) {
let sender = event.sender.id;
let text = event.message.text;
//apiai text request
let apiai = apiaiApp.textRequest(text, {
sessionId: 'MY_HOSTETTER' // use any arbitrary id
});
//get reponse from apiai
apiai.on('response', (response) => {
let apiaiText = response.result.fulfillment.speech;
//let apiaiType = response.result.fulfillment.type;
var apiaiMessages = response.result.fulfillment.messages;
//response from agent or domain
if(response.result.source == 'agent'){
for(let i=0;i<apiaiMessages.length;i++){
let amessage=apiaiMessages[i];
let replymessage = null;
//response from apiai agent
//which type of response get
switch(amessage.type){
case 0 :
//0 is text message
console.log(ITS TEXT MESSAGE);
replymessage = TextMessage(event, amessage);
break;
case 1 :
//1 is card message
console.log(ITS CARD MESSAGE);
replymessage = CardMessage(event, amessage);
break;
case 2 :
//2 is quick reply
console.log(ITS QUICK REPLY);
replymessage = QuickReply(event, amessage);
break;
case 3 :
//3 is image mesaage
console.log(ITS IMAGE MESSAGE);
replymessage = ImageMessage(event, amessage);
break;
case 4 :
//4 is custom payload
console.log(ITS CUSTOM PAYLOAD);
console.log(amessage.payload);
replymessage = amessage.payload;
break;
}
sendFBmessage(event, replymessage);
}
}else{
//handling domain response
console.log(ITS DOMAIN SAYING);
replymessage = TextMessage(event, amessage);
sendFBmessage(event, replymessage);
}
});
//if apiai gets error
apiai.on('error', (error) => {
console.log(error);
});
//apiai end
apiai.end();
}
a to je poslat zprávu FB
function sendFBmessage(event, replymessage){
let sender = event.sender.id;
request({
url: 'https://graph.facebook.com/v2.6/me/messages',
qs: {access_token: PAGE_ACCESS_TOKEN},
method: 'POST',
json:{
recipient: {id:sender},
message: replymessage
}
}, (error, response) => {
if(error){
console.log('Error : ', error);
}else if(response.body.error) {
console.log('Error : ', response.body.error);
}else{
console.log(Send Message Complete);
//return response.statusCode;
}
});
}
Problém je v tom, že se vysílá mimo provoz (textová zpráva zaslána rychle, jiné těžké obsah poslal pomalu dokonce to začíná dříve.)
Takže to, co chci, aby se „pomocí odeslání akce“ Před prvním zpráva úspěšně odeslána.
Existuje nějaký nápad na to? mohl byste mi pomoct?
dík,













