PircBotX Private Message - java

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)

Related

How can we develop a test method in Java (& Selenium Webdriver), for tracking 'a reset e-mail Notification', without verifying in mailbox?

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.

Slack API only picking up text field

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

Java Skype Api won't send messages

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?

How do I manually beam an NdefMessage with Android?

I have my NFC class which I assume people know what it looks like if you are looking at this question. So OnCreate, I do:
mNfcAdapter.setNdefPushMessageCallback(this, this);
to be able to send messages and then I do:
public NdefMessage createNdefMessage(NfcEvent event){
NdefMessage msg;
msg = new NdefMessage(new NdefRecord[] {
createApplicationRecord(this.messageToSend.getBytes())
});
return msg;
}
to send my message. and I have some code to receive a message as well but then I want to send another message back while the devices are still in "Connected" mode. How can I manually give a "send message" command?
Your application gets a single chance to send out the message using setNdefPushMessageCallback. Once the message has been transfered you get the completionCallback (if you want to). Afterwards you can't interact with NFC anymore.
Sending a second message after you got your completion is unfortunately not possible with the API as it is right no.
Technically there is no reason for this by the way. Google could add the functionality with ease. It would only take them a day or two. In Android 2.3 there already was an undocumented way to access the LLCP (base protocol of Android Beam) protocol from applications. This is gone since Android 3.0

WebSockets, GlassFish, Grizzly -- can't connect

I am trying to get started with WebSockets, and trying to write a simple application to send messages back and forth via a websoket.
However, it looks like the socket that I am trying to create never gets connected. Why can that be?
Below is the code of my WebSockets class. When .onConnect() is called, it logs:
I am socket, I was connected. Am i connected? - false
Update: in JavaScript, where I create the socket in question, the readyState is 1, which means "socket open, communication is possble".
import a.b.Misc; //writes logs.
import com.sun.grizzly.websockets.BaseServerWebSocket;
import com.sun.grizzly.websockets.DataFrame;
import com.sun.grizzly.websockets.WebSocketListener;
public class ChatWebSocket_v2 extends BaseServerWebSocket {
private String user;
public ChatWebSocket_v2(WebSocketListener... listeners) {
super(listeners);
}
public String getUser() {
if (user == null) {
Misc.print("User is null in ChatWebSocket");
throw new NullPointerException("+=The user is null in chat web socket");
}
return user;
}
public void setUser(String user) {
Misc.print("Just set user: " + user);
this.user = user;
}
#Override
public void onMessage(String message) {
Misc.print(message +"\n");
}
#Override
public void onMessage(byte[] message) {
Misc.print(new String(message) +" << Bytes\n");
}
#Override
public void onConnect() {
Misc.print("I am socket, i was connected. Am i connected? - " + this.isConnected());
}
#Override
public void onClose(DataFrame df) {
Misc.print("I am socket, i was closed");
}
}
If you're just trying to make a connection somewhere, you might want to try this instead. There is a live working demo and you can download the javascript code and play with it yourself. Note that the javascript code only works if you have it installed on a server (due to browser security because it's 'fancy'.) There is also a step by step browser-based client tutorial in the works that I will post as soon as it's ready. Most proxy servers haven't been upgraded to handle websockets so they will screw up connection request and most people won't be able to connect to websocket servers from work. Firefox 7 (release) or Google Chrome 14 or later support the latest version of the websocket protocol that the demo server runs.
If you want to try to get the grizzly demo working, you might have some debugging to do and maybe I'll help with that. Note that in comments below the article, other people said they couldn't get it working either and I haven't found any follow up. At this point it seems no better than the echo app above even if we do get it running and is possibly overly complicated and underly documented if you're just trying to get started. But if you want to try to get it running, you should 'git' the latest version of the code here, which was at least committed recently and may be fixed.
Then make sure that app.url in the application javascript file is set to your installation directory. His is hard-coded as:
url: 'ws://localhost:8080/grizzly-websockets-chat/chat',
If you're using Firefox 7, the javascript needs to be modified to use the Moz prefix, for example:
if (typeof MozWebSocket != "undefined") { // window.MozWebSocket or "MozWebSocket" in window
ok
} else if (window.WebSocket) { // he uses if ("WebSocket" in window)
ok
} else {
do your print "browser doesn't support websockets"
}
.... then if the browser supports websockets
websocket = new WebSocket(app.url); or
websocket = new MozWebSocket(app.url);
// depending on which it is.
The HLL websocket server demo code has this all sorted out.
(another) UPDATE: As I work through grizzly myself, I found on the Quick Start in the glassfish admin console, there's a hello sample that's pretty easy to set up and run. You'll find instructions there. The sample directory also contains a war file named: websocket-mozilla; so I guess its supposed to use websockets. Someone who's familiar with jsp should review the source code. All I can see is that it's using an http session. No mention of a websocket at all. It's a lot like the hello sample.

Categories

Resources