Chatbase messages are not showing in GUI - chatbase

I have integrated Chatbase into a voice application, when the user says a certain "Intent", it will be send and logged in Chatbase.
However, while the messages are sending fine (they are returning 200 in the send callback) - there appears to be nothing in the Chatbase console. I have read saying things can take 6 hours - it has now been 24 hours and there is still nothing!
Here is my implementation:
function sendChatbaseMessage(ad, intent) {
Chatbase.setApiKey(process.env.MY_CHATBASE_ID)
.setPlatform('Alexa')
.setVersion('1.0')
.setAsTypeUser()
.newMessage()
.setTimestamp(Date.now().toString())
.setMessage(`STATE: ${ad.Session[SessionVars.SkillState]}`)
.setUserId(ad.Util.getUserId())
.setIntent(intent)
.setAsHandled()
.setCustomSessionId(ad.Util.getSessionId())
.send()
.then((data) => {
console.log("Chatbase message sent: ", data.getCreateResponse())
})
.catch((err) => {
console.log("Error sending chatbase message", prettifyJSON(err.stack))
})
}

The information I was logging in my app was showing the the "cohorts" section of the web GUI.

Related

How do I mention user in teams channel incoming webhook?

I am unable to find any documentation available where I can mention a user for every message sent in a teams channel. I have to use an incoming webhook to send messages to the channel.
The messages will be sent from an azure function. This is the code I have tried so far.
axios
.post(
'https://name.webhook.office.com/webhookb2/xxx#xyz/IncomingWebhook/xxx/xxxb',
{
'#type': 'MessageCard',
'#context': 'http://schema.org/extensions',
themeColor: '0072C6', // light blue
summary: 'Summary description',
sections: [
{
activityTitle: title,
text: message
}
]
}
)
.then(
(resolvedValue) => {
resolve(`Sent message to teams ${resolvedValue}`);
},
(error) => {
reject(error);
}
);
I want to mention a user so that they get alerted when the message arrives.
Please go through User mention in Incoming Webhook with Adaptive Cards which talks about adding #mentions within an Adaptive Card body for incoming webhooks.
Please check Format cards with Markdown to add formatting in cards.

twitch js bot subscription response

I am writing a bot for the twitch platform, and I want to make it respond to users who have subscribed to the channel.
I found USERNOTICE for this in the documentation https://dev.twitch.tv/docs/irc/commands#usernotice
But I didn't quite understand how to use it.
Something like this?
client.on("message", () => {
client.say(config.get('channel'), '/usernotice message');
});
Just call the /usernotice command and it should respond to this subscription message?
It's just difficult to test all this and I would like to have a more or less specific solution.
UPDATE
Also in old documentation I found this code
chatClient.onSub((channel, user) => {
chatClient.say(channel, `Thanks to #${user} for subscribing to the channel!`);
});
chatClient.onResub((channel, user, subInfo) => {
chatClient.say(channel, `Thanks to #${user} for subscribing to the channel for a total of ${subInfo.months} months!`);
});
chatClient.onSubGift((channel, user, subInfo) => {
chatClient.say(channel, `Thanks to ${subInfo.gifter} for gifting a subscription to ${user}!`);
});
But it throws an error - TypeError: client.onSub is not a function
Is there any way to use it now?
chatClient.on('sub', (channel, user) => {
chatClient.say(channel, `Thanks to #${user} for subscribing to the channel!`);
});
On the assumption you are using tmi.js you should be looking at the tmi.js documentation rather than twitch's documentation. This documentation can be located here
in the documentation they have an example for a subscription event which can be found here:
https://github.com/tmijs/docs/blob/gh-pages/_posts/v1.4.2/2019-03-03-Events.md#subscription
client.on("subscription", (channel, username, method, message, userstate) => {
// Do your stuff.
});

Messages order of smooch - whatsapp

I have a bot and I use smooch to run the bot on whatsapp.
I use 'smooch-core' npm for that.
When I send a lot of messages one after the other sometimes the messages are displayed in reverse order in whatsapp.
Here is the code for sending messages:
for (const dataMessage of data) {
await sendMessage(dataMessage);
}
function sendMessage(dataMessage) {
return new Promise((resolve, reject) => {
smoochClient.appUsers.sendMessage({
appId: xxxx,
userId: userId,
message: dataMessage
}).then((response) => {
console.log('response: ' + JSON.stringify(response), 'green');
resolve();
}).catch(err => {
console.log('error: ' + JSON.stringify(err), 'red');
reject(err);
});
});
All dataMessage looks like this:
{
role: "appMaker",
type: "text",
text: txt
}
I tried to see how I could arrange it, and I saw that there was an option to get the message status from the webhook, and then wait for each message to arrive for the appropriate status. And only then send the following message.
But I would like to know is there something simpler? Is there a parameter that can add to the message itself to say what its order is? Or is there something in the npm that gives information about the message and its status?
In the doc below, Whatsapp mentions that they do not guarantee message ordering.
https://developers.facebook.com/docs/whatsapp/faq#faq_173242556636267
The same limitation applies to any async messaging platform (and most of them are), so backend processing times and other random factors can impact individual message processing/delivery times and thus ordering on the user device (e.g. backend congestion, attachments, message size, etc.).
You can try to add a small [type-dependent] delay between sending each message to reduce the frequency of mis-ordered messages (longer delay for messages with attachments, etc.).
The fool-proof way (with much more complexity) is to queue messages by appUser on your end, only sending the next message after receiving the message:delivery:user webhook event for the previous message.

Chatbot messages do not show up in Facebook Messenger chat heads

I am developing a chatbot for Facebook Messenger using Microsoft Bot Framework. The bot sends the user proactive messages (reminders). Unfortunately, for some reason the messages never show up in a chat head (the Android widget for conversations), nor pop up a chat head if it wasn't present on the screen before. It does happen for other chatbots (Jarvis, for example).
This is the code that sends the reminders:
Reminder.find({ next_reminder: { $lte: new Date() } }, (err, res) => {
if (err !== null) {
return console.error(err);
}
res.forEach(reminder => {
// Build a notification message and address it to user who created the reminder
const msg = new builder.Message().text('...');
bot.beginDialog(reminder.user_address, '*:/sendReminder', {message: msg, nudnik: nudnik});
});
});
};
};
I have also tried bot.send(msg, () => ....) and session.beginDialog('sendReminder', msg). However, there is still no indication from Messenger when the message is received. What could go wrong here?
OK, I figured it out! Apparently, the default notification setting for a Facebook message is not to show a notification. To change it, in NodeJS you should add channel-specific data to the message with the following code:
msg = msg.sourceEvent({
facebook:
{notification_type: 'REGULAR'}
});
You can discover more in official documentation by Microsoft (here and here) and also in this Github discussion.

get_started button sends messaging_postbacks callbacks thrice

Hi I am using nodejs and developing a bot on facebook messenger platform. I have my webhook subscribed only to messages and messaging_postbacks events. However, when I test the bot, it seems to send callback three times. This is my webhook code
server.post('/', (req, res, next) => {
let postback = req.body.entry[0].messaging[0].postback;
if (postback.payload === 'Greet User'){
console.log(postback);
}
}
When I test my bot, the postback object gets printed thrice as below.
{ payload: 'Greet User', title: 'Get Started' }
{ payload: 'Greet User', title: 'Get Started' }
{ payload: 'Greet User', title: 'Get Started' }
Any help how to avoid it? I read in some of the posts here that I should deselect message_reads and message_deliveries subscriptions. But I do not have those selected anyways. Not sure what else I am missing? Please help me.
I have found the problem after some more searching on the net and debugging it myself. In case, if others reading this might be interested to know, the issue was I was not sending back 200 status back to facebook. I found the hint regarding the need to do that in this stack overflow post.
Facebook webhook making multiple calls for the same message?
After sending the 200 response, I m not getting this issue. So relieved :)

Resources