how do I bind a bot to a specific chat on discord - chat

I have a couple of bots running on the same server and they are responding to the same messages. I want to bind each bot to different chat channel so they would only respond to the messages meant for certain bots.

bot.on("message", message => {
if (message.channel.id != config.singleChannelID) return;
//do stuff
});
This will make the bot only listen to one channel.
However, what you really want to be doing is changing the command prefix for one for the bots.
Example:
bot1: ?help
bot2: !help

Related

Display message 'user typing...' to everyone, including sender, if I am typing a message, VUE JS and socket.io

I am using vuejs and socket.io in my application. The task is this: if I type a message in a dialogue with the user, display a message to both the interlocutor and myself, that I am typing a message.
How can I implement this?
Socket.io gives you lots of options to send messages across the board. What I always found very helpful is the Emit cheatsheet from the official docs (https://socket.io/docs/emit-cheatsheet/).
Here are some of the methods on how to broadcast messages to all clients including sender.
io.on('connect', onConnect);
function onConnect(socket) {
// sending to all clients in 'chat' room, including sender
io.in('chat').emit('typing', 'User xy is typing');
// sending to all clients in namespace 'chatNamespace', including sender
io.of('chatNamespace').emit('typing', 'User xy is typing');
// sending to a specific room in a specific namespace, including sender
io.of('chatNamespace').to('chat').emit('typing', 'User xy is typing');
}
Now this of course are just example methods. You would need to wrap this into your own business logic and probably register some socket event listeners to get this going.

Is it possible to have Lync communicate with a REST API?

I have created a basic REST API where a user can ask for an acronym, and the web-page will return the meaning of the acronym via a POST call.
The majority of my end-users don't use the Internet as much as they use the Microsoft Lync application.
Is it possible for me to create a Lync account, and have it pass questions to my API, and return the answers to the user? Meaning the user just needs to open a new chat in Lync rather than a new web-page.
I'm sure this is possible, but I can't find any information on Google or on the web. How can this be accomplished?
Thanks very much.
Edit :
Adding a bounty in the hopes of someone creating a simple example as I believe it would be very useful for a large number of devs :).
Yep, absolutely. UCMA (the Unified Communications Managed API) would be my choice of API to use here, and a good place to start - UCMA apps are "normal" .net applications, but also expose an application endpoint, which can be added to a user's contact list. When users send messages, that can trigger events in your application so you can take the incoming IM, do the acronym translation and return the full wording.
I have a bunch of blog posts about UCMA, but as of yet no defined collection of "useful" posts to work through, but coming soon! In the meantime, feel free to browse the list.
-tom
To elaborate on Tom Morgan's answer, it would be easy to create an UCMA application for this.
Create an UCMA application
Now this doesn't have to be complicated. Since all you want is to receive an InstantMessage and reply to it, you don't need the full power of a trusted application. My choice would be to use a simple UserEndpoint. As luck would have it, Tom has a good example of that online: Simplest example using UCMA UserEndpoint to send an IM.
Make it listen to incoming messages
Whereas the sample app sends a message when it is connected, we need to listen to messages. On the UserEndpoint, set a message handler for instant messages:
endpoint.RegisterForIncomingCall<InstantMessagingCall>(HandleInstantMessagingCall);
private void HandleInstantMessagingCall(object sender, CallReceivedEventArgs<InstantMessagingCall> e)
{
// We need the flow to be able to send/receive messages.
e.Call.InstantMessagingFlowConfigurationRequested += HandleInstantMessagingFlowConfigurationRequested;
// And the message should be accepted.
e.Call.BeginAccept(ar => {
e.Call.EndAccept(ar);
// Grab and handle the toast message here.
}, null);
}
Process the message
There is a little complication here, your first message can be in the 'toast' of the new message argument, or arrive later on the message stream (the flow).
Dealing with the Toast message
The toast message is part of the conversation setup, but it can be null or not a text message.
if (e.ToastMessage != null && e.ToastMessage.HasTextMessage)
{
var message = e.ToastMessage.Message;
// Here message is whatever initial text the
// other party send you.
// Send it to your Acronym webservice and
// respond on the message flow, see the flow
// handler below.
}
Dealing with the flow
Your message flow is where the actual data is passed around. Get a handle on the flow and store it, because it's needed later to send messages.
private void HandleHandleInstantMessagingFlowConfigurationRequested(object sender, InstantMessagingFlowConfigurationRequestedEventArgs e)
{
// Grab your flow here, and store it somewhere.
var flow = e.Flow;
// Handle incoming messages
flow.MessageReceived += HandleMessageReceived;
}
And create a message handler to deal with incoming messages:
private void HandleMessageReceived(object sender, InstantMessageReceivedEventArgs e)
{
if (e.HasTextBody)
{
var message = e.TextBody;
// Send it to your Acronym webservice and respond
// on the message flow.
flow.BeginSendInstantMessage(
"Your response",
ar => { flow.EndSendInstantMessage(ar); },
null);
}
}
That would about sum it up for the most basic example of sending/receiving messages. Let me know if any parts of this need more clarification, I can add to the answer where needed.
I created a Gist with a full solution. Sadly it is not tested because I'm currently not near a Lync development environment. See UCMA UserEndpoint replying to IM Example.cs.
I never used Lync but while I was looking at the dev doc, I stumble upon a sample which could be what you're looking for.
Lync 2013: Filter room messages before they are posted
Once you have filtered the messages, you just need to catch the acronym and call your custom code that calls your API.
Unless I'm missing something, I think you could do it with a simple GET request as well. Just call your API like this yoursite.com/api/acronym/[the_acronym_here].
You can use UCWA (Microsoft Unified Communications Web API),is a REST API.For detail , can reference as the following..
https://ucwa.lync.com/documentation/what-is-lync-ucwa-api

Web Sockets - Send messages to all clients

I am completely new to Web Sockets, I have applied them to my chat so now it looks something like this:
<script type='text/javascript'>
var connection = new WebSocket("ws://echo.websocket.org"); //"public" websocket server
connection.onopen = function () {
console.log('Connection: OK.');
};
connection.onerror = function (error) {
console.log(Error: ' + error);
};
connection.onmessage = function () {
$('#chatbox').load('/chatbox.php');
};
$(document).ready(function() {
$('#chatOK').click(function(event) {
//something
connection.send('Get new messages.');
});
});
</script>
It works well for one client, when I enter message it updates the chatbox but only mine, but I want to update it for everyone (=all users who have opened chat window). So how can I send with WebSockets message to all clients?
You cannot do this with the websocket.org echo server - this just echos whatever you send it back to the sender.
You need a server which handles the distribution to all clients. This is easiest done using the Publish & Subscribe messaging pattern:
All chat messages are published to a common topic, e.g. "myChatRoom_1".
All connected clients indicate to the server that they are interested in messages to "myChatRoom_1" (that's the subscription).
Now when the server receives a published event for "myChatRoom_1" it can distribute it to all subscribers.
Take a look at this demo to see this in action.
It's based on Crossbar.io, an open source application router, which does PubSub out of the box, without an additional backend. So if you used this, you'd need to implement just the changes to your browser chat clients.
If you want to integrate with your PHP backend (e.g. since this stores the chat messages somewhere), there is a PHP library for connecting to Crossbar.io as well.
Full disclosure: I work for Tavendo, who are the maintainers of the Crossbar.io project.

Create Group like WhatsApp, BBM in XMPP with (a)Smack

Can I implement groupchat like WhatsApp or BBM in XMPP Asmack? I'm using Openfire Server.
I already implemented the basic multiuserchat in XMPP (http://xmpp.org/extensions/xep-0045.html), but it's not contain all the features that i needed.
I need the full features of group chat like :
groups can persist user no matter if they are online or not.
deliver offline messages to a group member (when he comes online).
Should I customize the server? or there are any Standard about this group feature?
I really need help for this problem.
Thank you.
You should use a packet listener for group chat messages. Run this packet listener in a service so that group chats are update even when the app is not running in foreground. Then check the sender id from packet and update your data base accordingly. Check the code below.
PacketFilter filter = new MessageTypeFilter(Message.Type.groupchat);
yourXmppConnection.addPacketListener(new PacketListener() {
#Override
public void processPacket(Packet packet) {
Message message = (Message) packet;
String received_message=message.getBody();
String from_user=message.getFrom();
// Add incoming message to the list view or similar
}
}
}, filter);

openfire get online users

I'm using OpenFire server for instant messaging and JSJaC JavaScript library on the client. I'm new in XMPP technology.
What I want is on load I want to send a list of users and receive status for each. Something like
$(function(){
var UserList = ["Isis", "Jackob", "Oybek"];
con.send(UserList, OnComplete);
});
function OnComplete(myList){
for (el in myList)
if (el.IsOnline) {
// Do DOM Stuff
}
}
Is it possible?
I've been looking for the documentation, examples and other similar responses but didn't find anyting.
You can't query for presence. You can subscribe to presence. If you send your own presence in, the server will send you the current presence of everyone you have subscribed to, as well as every change they make to their presence from there on in. There's no way to tell when you're "done" getting presence, because you're never done. Just set up a callback to do something interesting whenever you get a presence change from the person you are subscribed to, and you'll be in good shape:
con.registerHandler('presence_in', function(p) {
var from = p.getFromJID()
// do something interesting with p, from, etc.
});