I'm trying to send a message with attachments to a slack chat, using a slack bot. The connections to the api is done via WebSocket, and until now, everything works fine, everything but sending a message with attachments.
Here is the code snippet that sends the message:
public final void replyInteractive(WebSocketSession session, Event event, InteractiveMessage reply) {
try {
reply.setText(encode(reply.getText()));
reply.setType(EventType.MESSAGE.name().toLowerCase());
if (reply.getChannel() == null && event.getChannelId() != null) {
reply.setChannel(event.getChannelId());
}
session.sendMessage(new TextMessage(reply.toJSONString()));
if (logger.isDebugEnabled()) { // For debugging purpose only
logger.debug("Reply (Message): {}", reply.toJSONString());
}
} catch (IOException e) {
logger.error("Error sending event: {}. Exception: {}", event.getText(), e.getMessage());
}
}
And this is the json this code is sending:
{"type":"message","channel":"D4CJ8B337","text":"New book!","attachments":[{"fallback":"Something went wrong","color":"#3AA3E3","title":"Do you want to buy this book?","actions":[{"name":"Buy","value":"Yes","text":"Buy","type":"button"},{"name":"No","value":"No","text":"No","type":"button"}],"attachment_type":"default","callback_id":"Djisda"}]}
But, as I said, only the text field, "New book!", is being picked up and being shown in the chat. The whole message seems to be valid when I tested it using the Slack Message Builder.
I guess that's it, thanks in advance.
I found the problem. The RTM API does not accept attachments in messages.
From the Slack docs (https://api.slack.com/rtm):
The RTM API only supports posting simple messages formatted using our default message formatting mode. It does not support attachments or other message formatting modes.
To send attachments, you need to use the chat.postMessage method https://api.slack.com/methods/chat.postMessage
Related
I am developing UI Automation for testing a web app and currently confronted with, writing a test method to track if an email notification has been sent to a recipient. BUT, the challenge here is NOT to wait for some time and then checking in the recipient's mail box, but to be able to track the outgoing request for verification on the Web App itself.
Here is my current Code checking if mail URL is there or not after triggering the email notification.:
#Test
public void chkEmailNotif() {
try {
PO.clickEmailUrl(); //PO is a page object class
assertTrue(PO.MailFrameSeen());
PO.clickYes();
System.out.println(" Clicked on Yes button of the Mail frame Box ");
assertFalse(!PO.isMailurlSeen());
} catch (Exception e) {
System.out.println ("Catched exception e" + e )
}
}
Any suggestions are welcome.
Thanks in advance.
Mock the mailbox and check the message is sent. Set the configuration to use the mock or the real mailbox in a file that changes with the environment.
I've started on making my own Skype app using Java Skype Api from taksan
https://github.com/taksan/skype-java-api
(I prefer Java instead of C# because I don't know C# yet)
But my simple method on sending message doesn't work. I don't know if I'm missing something or they updated skype and therefore this api is outdated.
I tried two methods in Java FX called from a button. Both should send testing message to one of my friends. And yes, I've allowed the program in skype.
private void sendMsg2() throws SkypeException {
Skype.chat("skype_ID").send("Sending test message ...");
}
private void sendMsg(Friend[] friends) throws SkypeException {
for (Friend akt : friends) {
if (akt.getId().equals("friend's skype ID")) {
akt.send("Test message 2");
System.out.println("Sending test message 2...");
}
}
}
Both have same results. Message won't send. Look at the picture: http://imgur.com/dfXyV1t
I'm trying to send message to one person (so it's not chat group). Any suggestions please?
when a user executes a command, I would like to send the output back to only that user, not the channel.
I'm using the PircBotX framework.
My Code:
public void onMessage(MessageEvent<PircBotX> event) {
if (event.getMessage().equalsIgnoreCase("!test")){
event.respond("Test Successful.");
}else if (event.getMessage().split(" ")[1].equalsIgnoreCase("!test2")){
event.getChannel().send().message("this response works");
event.respond("This response works");
event.getUser().send().message("but this does not work");
}
}
According to the documentation, event.getUser().send().message("XYZ"); should be a private message.
The documentation also states bot.sendMessage should be a private message, but that this doesn't work either.
For both of these, the console output looks completely normal.
One thought I have as to the origin of the issue: I'm building this as a Twitch.tv chat bot. It is possible (although their API page does not mention this) that private messages are disabled.
are you trying to send a whisper ?? if so take a look at this https://discuss.dev.twitch.tv/t/sending-whispers-with-my-irc-bot/4346/6 you need to connect to an extra irc server to send whisper/private messages
try event.respondPrivateMessage("response");
See pirocbotx-docs->MessageEvent.respondPrivateMessage(String response)
Why is it not sending this email ? my log. i is executing it right on the run time but no emails are send out.
findViewById(R.id.feedback_submit).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
GMailSender sender = new GMailSender("senderemailaddress#gmail.com", "password");
sender.sendMail("This is Subject",
"This is Body",
"senderemailaddress#gmail.com",
"recipientemailaddress#gmail.com");
Log.i("Status", "Working");
} catch (Exception e) {
Log.i("Status", "Not Working");
Log.e("SendMail", e.getMessage(), e);
}
}
Since you are using GMailSender any exception thrown will be consumed by the class and you will have no way of knowing whether the mail was sent successfully or not.
I had a problem like that once, make sure that the network you are in is allowed to send mails. It has to do with the way SMTP protocol is setup. I suggest you use the JavaMail API you will get a better understanding of how everything works. Here's a link to a good tutorial
http://www.tutorialspoint.com/java/java_sending_email.htm
Make sure all your JAR files are in your project as well
I have written a code in order to be able to launch the default email service provider which is outlook for me. this is the code i have:
if(role.getValue().equals("1")) {
Desktop desktop = Desktop.getDesktop();
String message = "mailto:username#domain.com?subject=New_Profile&body=NewProfile";
try {
desktop.mail(uri);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I am trying to attach something to the email automatically but its not working. Instead, will it be possibly to retrieve some data from input fields in my program and automatically add that data as body to the email?
I tried embedding a statement somehow, but its not working. could someone please advise?
Desktop desktop = Desktop.getDesktop();
String message = "mailto:username#domain.com?subject=New_Profile&body=person.getPdfName()";
Why would the code above not do anything? Is person.getPdfName() misplaced?
Have a look at these answers, not sure any of them solve your problem, but they do give a decent description of why its not that simple. Not all email clients support attachments in this way.
Start Mail-Client with Attachment?
How to open an email client and automatically attach file in java
http://forums.devshed.com/windows-help-34/defaut-mail-client-with-attachment-on-xp-71305.html
Java has an API that is able to send messages and perform all the necessary functions, such as attach files. Check the class MimeMessage to help you.
In your case, I believe that the body of your message would become a simple text containing the name of the PDF, isn't that so?