In SLACK, Is it possible to create commands for an app which post messages to different channels?
This is what I am trying to achieve:
I run a Slash command from my DM which will post a message in a channel, which I am not a part of.
A member of that channel now runs another command to reply me and his response should be received by me either in my app’s messages or in the same channel but visible to me only.
Can this be achieved ?
A bot token, (xoxb) can send messages to any public channel using the chat.postMessage method and the [chat:write/public][1] scope. For that, the bot does not need to be a member of the channel. The bot can also send 1:1 DMs to users if you pass their user id as the channel parameter in a call to chat.postMessage but the bot won't be able to post into a private channel or multi-person DM it is not a member of. To send messages in-channel that can only be viewed by a specific user, check out [chat.postEphemeral][1], the user seeing this message must be a member of the channel.
What you mentioned in the question can be achieved using Slack's 'Interactivity' features. (Slash Commands & App Shortcuts)
You'll need to implement code to capture 'command', and then use Slack's WebAPIs to achieve the result.
(Chat APIs)
Related
If I have a bot in a group, and I want to make the bot respond only if it was mentioned in the message, is there any way to achieve this?
When a message contains a mention by username then the Message object contains a MessageEntity with MessageEntity.type equals to 'mention' (since bots always have username).
You can check MessageEntity.offset to get the position of the entity in the text of the message, then parse the text of the message to check if the username mentioned is you bot's username.
Consider that by default bots run in privacy mode
A bot running in privacy mode will not receive all messages that
people send to the group. Instead, it will only receive:
Messages that start with a slash ‘/’
Replies to the bot's own messages
Service messages (people added or removed from the group, etc.)
Messages from channels where it's a member
I'm sending automated emails using java mail to my colleagues in different states (all within our company). I set the return path as their manager's emails. In case the recipient's mail box is full, their manager would get an undeliverable email notification.
Is there any way I can customize that undeliverable message, so that their managers who receive the undeliverable notification, would also get instructions on how to handle those emails and "couch their subordinates" ?
I couldn't find any documentation on this. Is this even possible ?
The undeliverable message is sent by your mail server. Depending on the mail server you're using, you might be able to customize the returned message.
For some cases you could try to enable the mail.smtp.reportsuccess session property and use the results to gather the invalid addresses. Then use the com.sun.mail.dsn to create a custom delivery status notification to send it to the return address.
How I can send file from one client (A) to another one (B) via socket? and vice versa, send file from B to A. I mean that make the client sender and receiver at the same time.
In other word, when muticlient connect to server, how I distinguish between clients ?
You need to implement you own communication message format in short a simple protocol .
You keep a list of all active sockets in a shared list/map , and based on the request from the message you pick up the apt client and push the desired message to that.
You can implement the actual message format as you want, but this can be the blueprint.
In this case lets say your client A sends message : 1. Client Id 2. File Start 3 X . File Content 4. File End
as soon as you get a connection you get the target client id , the file start message lets you understand the next message just needs to be diverted to target and file End message defines the transfer complete.
Also, you may would like to send Acknowledgement message from server to client, in order to eradicate transfer issues.
It is good way to manage client using their id(i.e. a unique long or string or any other for each user). At the time of connection to socket client send their id , store that is in collection. And when a user(Client) want to send file send with own id and Id of that user(Client) want to send.
I am trying to write a client server application that communicate using Message Objects(Message Class is defined in my application). there is a scenario in which i want to transfer file between them. First I must send a message to client to notify it about specific file information and after that the file itself is going to be written to channel.
The problem is how can I handle this scenario in client?
Is it a good solution to remove Message handler after receiving message and replace it with a byte array handler?
what are the alternatives?
Sure you can just modify the pipeline on the fly. We do something similar in our portunification example[1].
[1] https://github.com/netty/netty/blob/4.0/example/src/main/java/io/netty/example/portunification/PortUnificationServerHandler.java
I have a scenario whereby I want to inform users of my site that someone has commented on an article on which they have also commented. This is a lot like the way that SO notifies me when someone responds to a question!
Server side, I persist the comment and then look up all users who commented on the same article. I then broadcast (I'm using Atmosphere):
PushContext pushContext = PushContextFactory.getDefault().getPushContext();
for(User u : users){
// channel name, message
pushContext.push("/user_" + u.id, "someone commented! blah blah");
}
The "channel" I am broadcasting to is the user's "own" channel, since I don't want every user to be notified. I use the user's ID in the channel name to achieve this.
Is this the right way to do ensure only relevant users get notified?
I guess I also want to do two more things:
Only push to users whom I believe are still online. If they aren't online, then it's a waste of resources pushing to them.
Encrypt the message, because otherwise anybody could listen for my messages, if they know my user ID.
Is there anything else I need to think of?
SO uses WebSockets, for example when a comment is made on this posting, you get a notification in your status bar at the top left of the SO page.
When the page is loaded, the browser makes a protocol upgrade request which looks like this:
Request URL:ws://sockets-se.or.stackexchange.com/
Request Method:GET
Status Code:101 Switching Protocols
Request Headersview source
Connection:Upgrade
Cookie:__qca=P0-1697817643-1763440830313; __utma=27376923.959753990.1338240830.1353943751.1384115154.33; __utmc=27693525; __utmz=27699983.1356175156.31.31.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
Host:sockets-se.or.stackexchange.com
Origin:http://stackoverflow.com
Sec-WebSocket-Extensions:x-webkit-deflate-frame
Sec-WebSocket-Key:6qFl45+6gZ526yMMo79zWQ==
Sec-WebSocket-Version:13
Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00
Response Headersview source
Connection:Upgrade
Sec-WebSocket-Accept:B4h2G+gi78iNZZXg+o6iAztgF1I=
Upgrade:websocket
(Challenge Response):00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
The socket is then open, and the server can send updates to the browser. For example, a notification of my comment is received by the browser as:
{"action":"1-question-12993099","data":"{\"a\":\"comment-add\",\"id\":12993099,\"commentid\":19334206,\"acctid\":1298157}"}
It doesn't contain the actual comment; it appears that this is simply used to tell the browser to show the red icon. When you then click, it makes a request to get the page, including the comment. The question ID (12993099), comment ID (19334206) and account ID (1298157) is contained in that frame.
I cannot see anything in the above which would stop some hacker creating a web socket to listen to your notifications. The cookies look to me to be Google Analytics cookies to me, or at least the second and third ones do. Perhaps the first is some code which you wouldn't know, had I not just published it (no worries, I change it!).
In your example of Atmosphere, I know that when Web Sockets does not work, it defaults to long polling, which then requests a URL with the channel name in it. So you could get the client to generate a channel name which only it would know and associate that with the logged in user. But anyone sniffing the network would again have access to your traffic, so you'd have to secure it using secure web sockets (WSS) and HTTPS (for long polling fallback).