Integrate chatbot into any third-party messaging API - api

I want to make a unified "inbox" for messages from across multiple platforms, some of them are widely supported by all mejor chatbot services, like Facebook Messenger, others are more obscure like WhatsApp, but others are plain unsupported (like Steam Web Chat).
I've encountered several solutions that have some sort of "one-click" integration for the most popular messengers, but I can't find one that will let you integrate third-party messengers (which ideally have an API to read/send messages at the very least) into a chatbot-like service. Is there such a thing out there?
PS: I don't really care about fancy AI conversational support, I'd just like to receive all messages into, say, one webhook I can then act on, and also be able to reply to them.

API.ai doesn't have an 'integration pooling' architecture, it treats each platform as a separate integration or conversation. Given that, you'll have to build your own server side message pooling solution which plugs into all your 3rd party APIs, and then pools/queues messages across all streams before passing to API.ai, and with some messageID/tracking system on your server side solution to remember which 3rd party API to respond to with API.ai response. Something like this as an aggregate/pooling function should work:
var queue = [];
var queueProcessing = false;
function queueRequest(request) {
queue.push(request);
if (queueProcessing) {
return;
}
queueProcessing = true;
processQueue();
}
function processQueue() {
if (queue.length == 0) {
queueProcessing = false;
return;
}
var currentRequest = queue.shift();
//Send to API.ai
request(currentRequest, function(error, response, body) {
if (error || response.body.error) {
console.log("Error sending messages!");
}
processQueue();
});
}

What I would do is have a Node.js backend.
Direct every messaging integration to it and then direct that to API.AI.
So the flow would be like this:

There is a service called Message.io which does I believe what you want. They support the widest range of platforms.
Message.io sits between your bot and the messaging platforms, you receive messages in a standardized way from Message.io, and when sending messages out to users, it converts it to the appropriate format for the platform you're responding to.

Related

Is it possible to use websockets to send a request and get a response right after (without the publisher/subscriber structure)?

I am using spring-websocket together with Kotlin Multiplatform, SockJS and StompJS.
I've got my application up and running, mainly using this tutorial from Spring. The frontend is able to send messages to the backend (via the #MessageMapping annotation), which responds back to frontend (via the #SendTo annotation).
The frontend code currently looks like this:
val socket = SockJS("http://localhost:8080/my-app")
val stompClient = Stomp.over(socket)
stompClient.connect(json(), { frame ->
stompClient.subscribe("/topic/a-topic", { message ->
// message handling code
})
})
stompClient.send("/app/hello", null, "")
The subscription approach is useful when an action from some user needs to affect all users (like sending a message in a group chat). However, there are times when some actions should affect only the user who started the action, and that is my problem.
Ideally, I would like to do something to the likes of this:
val socket = SockJS("http://localhost:8080/my-app")
val stompClient = Stomp.over(socket)
stompClient.connect(json(), {})
stompClient.send("/app/hello", null, "").then { response ->
// response handling code
}
But I don't know if it is possible.
I also thought about having a REST API handle this kind of request, but it doesn't seem optimal since there's the existing websocket connection already.
Any enlightment on the matter is appreciated.

Call web service at alerting in grafana

I'm using Grafana and set an alert in a graph, How can I call an external API or web service when alert fired? thanks.
So the goal is to get information into an external service. I am making the assumption that your particular external api / web service is not in the list of supported notification channels.
Personally in this case, I would suggest using the webhook notification channel option, as it gives a TON of information to work through / interact with:
{
"dashboardId":1,
"evalMatches":[
{
"value":1,
"metric":"Count",
"tags":{
}
}
],
"imageUrl":"https://grafana.com/assets/img/blog/mixed_styles.png",
"message":"Notification Message",
"orgId":1,
"panelId":2,
"ruleId":1,
"ruleName":"Panel Title alert",
"ruleUrl":"http://localhost:3000/d/hZ7BuVbWz/test-dashboard?fullscreen\u0026edit\u0026tab=alert\u0026panelId=2\u0026orgId=1",
"state":"alerting",
"tags":{
"tag name":"tag value"
},
"title":"[Alerting] Panel Title alert"
}
This can be sent to any service that is capable of receiving webhooks and translating them into whatever you need for your external API endpoint, I might suggest the following:
integromat.com (Free account gives 1000 operations / month)
n8n.io (OSS and self-hosted but limited direct integration... does have HTTP, so you can use that to interact with whatever (including internal stuff)
Once in either of these tools, you build a webhook receiver and then a workflow that will translate the action into the formats needed by your external API / service.

Which chat api has a good Search function?

I am developing a web app that is used for professional service professionals (accountants) to create shared workspaces (portals) for each client. These workspaces need a real-time Slack-like conversation across accountant and client -- and a key requirement is to be able to search the message history. I've looked at PubNub ChatEngine, Twilio, TalkJS, Applozic, Sendbird etc. but can't seem to find even one with this Search capability. Any suggestions?
With PubNub ChatEngine, you can use JavaScript to get past messages in a particular chat. You can write a few lines of JavaScript to filter the messages that are returned. For your use case, you would filter for your search input.
The documentation for this feature is here.
chat.search({
event: 'message',
sender: ChatEngine.me, // You can filter on a specific sender
limit: 20, // You can make a limit for the number of messages to recall and search through
start: "14375189629170609", // Optional beginning time token of messages to search through
end: "14375189629999999"
}).on('message', (event) => {
// Filter messages based on search input
}).on('$.search.finish', () => {
console.log('we have all our results!')
});

Leave a conversation with Skype Web SDK on page reload

We're building a web application using the Skype Web SDK (https://msdn.microsoft.com/en-us/skype/websdk/docs/skypewebsdk). We use both the audio and the IM capability to get connected to other parties.
Currently we're facing the following problem: If our application is in a conversation with another party (e. g. with a Skype for Business desktop client) and the user leaves or reloads the page, the other party doesn't get notified about the left user.
For audio conversations the result is the following: The other party is still in the call and the only indication of the leaving is that the other party can't hear anything.
For IM conversations the result is the following: If the other party sends an IM in this conversation it gets the notification that the message couldn't be delivered.
We've tried to leave the conversation before the unload of the page using the onbeforeunload event. The callback is executed both in IE 11 and Chrome, but only in Chrome the user actually leaves the conversation (tested with IM conversation since audio/video is not supported in Chrome).
window.onbeforeunload = function() {
// conversation is the conversation we're currently in
conversation.leave().then(function () {
client.conversationsManager.conversations.remove(conversation);
});
};
Since we rely on the audio capability we're not able to simply switch to Chrome only. Is there any way to ensure that the conversations are cleaned up on page reload/leave in Internet Explorer?
The problem with what you are trying to do is that the (on)beforeunload event does not wait around for asynchronous methods to complete so you are not guaranteed that leave() will execute nor the inner action to remove the conversation from the conversationsManager. I would suggest an approach similar to the following question - onbeforeunload confirmation screen customization or beforeunload
What you want to do is put the user into a state where the need to interact with a dialog which may (but also not guaranteed) give enough cycles to leave the conversation. In your case it might look something like the following:
window.onbeforeunload = function(e) {
// track if a conversation is live
if (_inActiveConversation) {
// conversation is the conversation we're currently in
conversation.leave().then(function () {
client.conversationsManager.conversations.remove(conversation);
});
var msg = 'Cleaning up active conversations...';
e.returnValue = msg;
return msg;
}
};
What you should also understand is that eventually the server side will remove that user from the conversation because the application is no longer processing incoming events. So the above is a best effort to clean up resources that will eventually be reclaimed.
You could also try to issuing a signOut request on the signInManager as that should allow the server to clean up resources related to that application on the server side.
window.onbeforeunload = function() {
...
_client.signInManager.signOut();
...
};

Architecture: Titanium Desktop against the Twitter Streaming API

I'm new to Titanium, and have started out by trying to build a (yet another) Twitter client. The problem I've encountered is that I would like to use Twitter's Streaming API, and I'm struggling to understand the best way to do that within Titanium Desktop.
Here's the options I see:
Don't use the Streaming API, it's not going to work.
Build a Python bridge that connects with a httpclient that supports streaming responses (required for the Streaming API, it never closes the connection). Let that client deliver the responses to a Javascript method that formats and outputs tweets as they come. (Problem here: How do I bundle the python libraries I need?)
Use the Javascript HttpClient shipped with Titanium SDK 1.1 in some clever way I'm not aware of.
Use the 1.2.0-RC2 release of Titanium SDK that ships with a HttpClient that has support for streaming responses. There's very little information in the Release notes to judge if the streaming support is enough to get things working with the Streaming API.
Use twstreamer, a javascript library for streaming support through a Flash intermediary. I've seen bug reports stating the Flash does not work well inside Titanium Desktop, but I'd love to be proven wrong.
Another way that I'm not yet thought of.
I'm hoping for all sorts of clever ideas of how I can get this working, and tips going forward. Thanks for reading!
I'm not at all familiar with Titanium, but looking through their docs your best bet is likely going to be to use Titanium.Process to fork something that can deal with streaming responses. There are plenty of lightweight options here, but note that if you want to use userstreams you'll need an option that supports OAuth and SSL
Here's how to do it (after LOTS of testing):
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET", "https://stream.twitter.com/1/statuses/filter.json?track=<Your-keyword-to-track>", true, '<Your-twitter-nickname>', '<Your-twitter-password>');
xhr.send();
var last_index = 0;
function parse() {
var curr_index = xhr.responseText.length;
if (last_index == curr_index) return; // No new data
var s = xhr.responseText.substring(last_index, curr_index);
last_index = curr_index;
console.log(s);
}
var interval = setInterval(parse, 5000);
setTimeout(function(){
clearInterval(interval);
parse();
xhr.abort();
}, 25000);