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
Related
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)
I'm using the simple-slack.api to send and receive Slack messages.
Is there a way to decide if a message was read?
I found that I can get the history of a channel, but the SlackMessagePosted does not contain any field if the message was read or not (the MessageSubType does not include it)
Its not possible.
The Slack API (e.g. channels.history or conversations.history) does not provide any information about which messages are unread and by whom.
The only thing you get is the total number of unread messages for your current user as defined by the token you are using (by setting the parameter unreads to true), but I guess that is not what you are looking for.
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.
I have built an external openfire component based on the Whack library by extending the AbstractComponent class. I want clients to subscribe to my component and receive presence notifications when the component goes online and offline. So my question is how we can deal with presence and presence subscriptions for external component based on AbstractComponent?
Currently I can respond to the presence request by using the handlePresence() method but how do should I add clients to the component roster (does external components allow for roster in the first place)?
#Override
protected void handlePresence(Presence presence){
if (presence.getType() == Presence.Type.subscribe){
System.out.println("The component has received Subscribtion request.");
Presence original = presence;
Presence response = new Presence();
//Swap the sender/recipient fields
response.setTo(original.getFrom());
response.setFrom(original.getTo());
//Convert the text to upper case
response.setType(Presence.Type.subscribed);
send(response);
}
}
Components do not have a roster provided by the server. You can store your own roster in a database if you need to. Some applications can get away with no roster at all (when they simply want to appear online to everyone).
To appear online to everyone (simplest approach, no roster storage required):
When you receive <presence type="subscribe"/> reply with <presence type="subscribed"/>
When you receive <presence type="probe"/> reply with <presence/> (or whatever status you want to be shown as)
To store a roster requires a bit more work, but allows you to keep track of who is authorized to see your presence, and whose presence you are authorized to see. In some cases you might prefer to use a normal client connection here, if you don't want to manage your own roster. Jack Moffitt wrote a blog post on the idea here: http://metajack.im/2008/08/04/thoughts-on-scalable-xmpp-bots/
Note that throughout this post I omit the 'to' and 'from' attributes on stanzas. It is up to the component to put a 'to' and 'from' on outgoing stanzas. All incoming stanzas will have a 'to' and 'from'.
Displaying a component's presence to users
The basic incoming stanzas you need to handle are:
<presence type="subscribe">
The sender wants to subscribe to your presence updates. You can either approve or decline this. If you approve, you should store the sender's JID in your database so you know you need to send them your presence updates when necessary.
Specification: http://xmpp.org/rfcs/rfc6121.html#sub-request-handle
<presence type="unsubscribe">
The sender wants to stop receiving presence updates from you. You should remove them from the list of people subscribed to your updates, and then send back <presence type="unsubscribed"> and <presence type="unavailable">.
Specification: http://xmpp.org/rfcs/rfc6121.html#sub-cancel-inbound (though the text is tailored more towards servers than components here).
<presence type="probe">
The sender is asking for your current presence. Simply reply with your latest presence stanza for that user. This is typically sent by the user's server when they log in.
Receiving presence of users in a component
Additionally if you want the component to know the presence of users, you need to send a subscription request to them: <presence type="subscribe">. You should be prepared to receive either an approval (<presence type="subscribed">) or denial (<presence type="unsubscribed">).
When the component first comes online, it can fetch the current presence for a user by sending <presence type="probe"> to each user. There is no need to do this more than once per user while the component is running - the user's server will automatically send you presence updates if the user approved your subscription request as above.
I have to send messages to many clients. But many of them bounce back. I want a list of those email addresses. How can I get that list from my Java application?
Make a special email address bounced#yourdomain.com where you will capture all bounced emails for analysis.
Add the following header to your sent emails:
Return-Path: <bounced#yourdomain.com>
Now the emails are going to bounce back to that address.
Read emails at that address from your java program from time to time, for example via IMAP (or depending on your server via a notification interface/whatever), and when you see an email address record it in your database
Note that if you are doing a newsletter app, you should not blacklist the email from the first time, but make count it's bounces, and blacklist it after 3-4 bounces (some people set their email to bounce when they go in vacation and such, so they need special taking care of).
I solve this question using
SMTPMessage msg = new SMTPMessage(getSession());
msg.setEnvelopeFrom(bounceAddr);
Please see the javamail doc and see it:
void com.sun.mail.smtp.SMTPMessage.setEnvelopeFrom(String from)
Set the From address to appear in the SMTP envelope. Note that this is different than the From address that appears in the message itself. The envelope From address is typically used when reporting errors. See RFC 821 for details.
If set, overrides the mail.smtp.from property.
Parameters:
from the envelope From address