I would like to use PubNub with Parse for a chat module. Could somebody explain me how can i send messages with text and images via PubNub to a user (only one-to-one)? I wanna use the PFUser usernames as the id of a user's private channel.
I've found this code in the PubNub help docs, but i've never seen code like this in objective-c. Where/how should i use this line?
curl https://pubsub.pubnub.com/publish/<PUB-KEY>/<SUB-KEY>/0/<CHANNEL-NAME>/0/%22Hellooooooo%22
It's also unclear for me that where should i store the messages? In Parse or can i store them only at PubNub? I'm not sure that the second variation is possible, because i didn't see any data storage at PubNub. Or for example i'm sending only the url's of the PFObjects that i store at Parse?
Parse + PubNub Publish Messages
You can publish messages inside of parse cloud to your mobile users to create chat experiences easily. If you want to send the messages directly from within Parse Cloud use the following code to send a message to a user:
Publish PubNub Message on Parse Cloud
Parse.Cloud.httpRequest({
url: 'https://pubsub.pubnub.com/publish/<PUB-KEY>/<SUB-KEY>/0/<USER-CHANNEL-NAME>/0/%22Hellooooooo!%22',
// successful HTTP status code
success: function(httpResponse) {
console.log(httpResponse.text);
},
// unsuccessful HTTP status code
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
You don't necessarily need to use Parse this way. You can instead send messages directly between users to each user's channel name. Sally has "channel-sally", and Bill has "channel-bill". You can publish and subscribe directly form your Objective-C App Code. Bill will subscribe to his own channel and a Sally to her channel.
Bob's App
// Define a channel
PNChannel *myChannel = [PNChannel channelWithName:#"channel-bob"];
PNChannel *friendChannel = [PNChannel channelWithName:#"channel-sally"];
// Receive Messages Sent to Me!
[PubNub subscribeOnChannel:myChannel];
// Send a Message to Sally
[PubNub sendMessage:#"Hello from PubNub iOS!" toChannel:friendChannel];
//(In AppDelegate.m, define didReceiveMessage delegate method:)
- (void)pubnubClient:(PubNub *)client didReceiveMessage:(PNMessage *)message {
NSLog(#"Received: %#", message.message);
}
Bob can receive messages on his own channel and he can send messages to Sally or any other of his friends.
Related
I am using spring-websocket together with Kotlin Multiplatform, SockJS and StompJS.
I've got my application up and running, mainly using this tutorial from Spring. The frontend is able to send messages to the backend (via the #MessageMapping annotation), which responds back to frontend (via the #SendTo annotation).
The frontend code currently looks like this:
val socket = SockJS("http://localhost:8080/my-app")
val stompClient = Stomp.over(socket)
stompClient.connect(json(), { frame ->
stompClient.subscribe("/topic/a-topic", { message ->
// message handling code
})
})
stompClient.send("/app/hello", null, "")
The subscription approach is useful when an action from some user needs to affect all users (like sending a message in a group chat). However, there are times when some actions should affect only the user who started the action, and that is my problem.
Ideally, I would like to do something to the likes of this:
val socket = SockJS("http://localhost:8080/my-app")
val stompClient = Stomp.over(socket)
stompClient.connect(json(), {})
stompClient.send("/app/hello", null, "").then { response ->
// response handling code
}
But I don't know if it is possible.
I also thought about having a REST API handle this kind of request, but it doesn't seem optimal since there's the existing websocket connection already.
Any enlightment on the matter is appreciated.
API Testing:
Currently, I am using Postman to test API response
I want to monitor a particular text in API response and get notified for example-
{
"productname": "PARLE",
"customer": "ABC",
}
If I get a customer name in the API response as ABC I want to get notified through mail or slack or anything.
Is this possible? if Yes please share me the inputs.
you can run periodic tests with a software like Overseer, and receive notifications using a Notify17 notification template (see the sample recipe).
You could use a test rule like:
http://myurl.com/path must run http with not-content '"customer": "ABC"'
To have an easy start with Overseer, you can check out the Kubernetes deployment example.
You can achieve your use case using Postman Monitors to send an email or send a slack message by following these steps:
Configure your monitor to run with an environment. (Reference: https://learning.getpostman.com/docs/postman/monitors/intro_monitors/)
In the test script of your Collection's Request, fetch the response using pm.response.json() (Based on the response structure you mentioned)
Use the following code snippet to determine whether the response contains what you need:
if (pm.response.json().customer === 'ABC') {
// no op
}
else {
postman.setNextRequest(null);
}
Here, if the condition is not met, then the next request that will be executed is null, which means that the collection execution will stop here. However, if the condition is met, this will not be set and the next request will be executed.
You can use various Public APIs to achieve tasks like send an email or send a slack message:
Gmail API | Slack API
Create a request below the current request titled 'Send notification'. Use the documentation provided to set the request up.
When your monitor runs, if the condition is not met, then postman.setNextRequest will be set to null and the 'Send notification' request will not run. However, if the condition is indeed true, then the request will run and you will receive a notification on the respective channel.
I am using openfire. I am able to add users and groups. But now stuck at send message from one user to another. I was going through libraries but not found any suitable. I tried xmpp bosh library but getting error:
"message": "Declaration of XMPPHP_BOSH::connect($server, $wait = '1', $session = false) should be compatible with XMPPHP_XMLStream::connect($timeout = 30, $persistent = false, $sendinit = true)",
"exception": "ErrorException",
The REST API Plugin does not provide the feature you are looking fore (1:1 messaging). The REST API Plugin is made to manage the Openfire Instance (Users, Groups, Channels etc.)
To send one to one messages, you could use the openfire chat plugin. (https://github.com/igniterealtime/openfire-chat)
Example:
POST /restapi/v1/chat/{streamid}/messages/{destination}
{
"body" : "desired message"
}
I am developing a web app that is used for professional service professionals (accountants) to create shared workspaces (portals) for each client. These workspaces need a real-time Slack-like conversation across accountant and client -- and a key requirement is to be able to search the message history. I've looked at PubNub ChatEngine, Twilio, TalkJS, Applozic, Sendbird etc. but can't seem to find even one with this Search capability. Any suggestions?
With PubNub ChatEngine, you can use JavaScript to get past messages in a particular chat. You can write a few lines of JavaScript to filter the messages that are returned. For your use case, you would filter for your search input.
The documentation for this feature is here.
chat.search({
event: 'message',
sender: ChatEngine.me, // You can filter on a specific sender
limit: 20, // You can make a limit for the number of messages to recall and search through
start: "14375189629170609", // Optional beginning time token of messages to search through
end: "14375189629999999"
}).on('message', (event) => {
// Filter messages based on search input
}).on('$.search.finish', () => {
console.log('we have all our results!')
});
Since 2 days I've been exploring the Telegram bot API, which is pretty neat. But there is one thing I can't figure out.
When you don't use the webHook but the /getUpdates call, you can tell the API via the offset parameter which message where processed by the server.
But how do you do this with the webHook in place? I keep getting the same message as an update. Which results in the server spamming the user with the same message.
The solution I came up with is as follows:
Receive an update from the webhook
Save the update_id
Reply to the user /sendMessage
disable the webHook /setWebhook?url=
Set the offset /getUpdates?offset={update_id+1}
Reinstate the webHook /setWebhook?url=https://mywebhook.domain.com
There must be a better way right? Anyone?
Ok, problem solved. It appeared that just a 200 (OK) wasn't enough (the body of my response was null. I've added a body to the response {}, and know it works fine.
You must say to telegram that you get updates successfully with this:
- 200 response code
&
- empty json like this {}
use This on webHook to get data from telegram servers:
// get the raw POST data
$rawData = file_get_contents("php://input");
// this returns null if not valid json
$jsonData = json_decode($rawData);
What HTTP status code are you returning on the page handling your webhook? It is possible that Telegram is attempting to retry your webhook endpoint because it's not receiving a status 200 (OK) from you.