Openfire send message using rest api in php - openfire

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"
}

Related

Kotlin for Volley, how can I check the JSON request for newer data in the API?

I'm working on an app that gets a list of documents/source URL from an api. I'd like to periodically check for new or updated contents within that API so users can update saved items in the database. I'm at a loss on the correct wording to search, thus Google and Stack Overflow have both failed me. My fetching function is below:
The URL for the API is https://api.afiexplorer.com
private fun fetchPubs() {
_binding.contentMain.loading.visibility = View.VISIBLE
request = JsonArrayRequest(
Request.Method.GET,
Config.BASE_URL,
JSONArray(),{ response ->
val items: List<Pubs> =
Gson().fromJson(response.toString(), object : TypeToken<List<Pubs>>() {}.type)
val sortedItems = items.sortedWith(compareBy { it.Number })
pubsList?.clear()
pubsList?.addAll(sortedItems)
// Hardcoded pubs moved to Publications Gitlab Repo
// https://gitlab.com/afi-explorer/pubs
_binding.contentMain.recyclerView.recycledViewPool.clear()
adapter?.notifyDataSetChanged()
_binding.contentMain.loading.visibility = View.GONE
setupData()
Log.i("LENGTH OF DATA", "${items.size}")
},
{error ->
println(error.printStackTrace())
Toasty.error(applicationContext, getString(string.no_internet), Toast.LENGTH_SHORT, true).show()
}
)
MyApplication.instance.addToRequestQueue(request!!)
}
private fun setupData(){
adapter = MainAdapter(applicationContext, pubsList!!, this)
_binding.contentMain.recyclerView.adapter = adapter
}
I tried using ChatGPT to see if that would get me started and that failed miserably. Also searched Google, Reddit and Stack Overflow for similar projects, but mine is a unique scenario I guess. I'm just a hobbyist and intermediate dev I guess. First time working with Volley, everything works, but I would like to find a way to send a notification (preferably not Firebase) if there is updated info within the API listed above. I'm not sure if this is actually doable.
Are you asking if you can somehow find if the remote API has changed its content? If so, how would that service advise you? If the service provider provides a web hook or similar callback you could write a server-based program to send a push notification to your Android app.
Perhaps you intent to poll the API periodically, and then you want to know if there is a change?
If you use a tool such as Postman or curl to easily see the headers of the API https://api.afiexplorer.com you will see, unfortunately, there is no Last-Modified header or ETag header which would allow you to easily determine if there was a change.
Next looking at the content of the API, the author does not provide an obvious version/change date, so no luck there.
What you could do is receive the content as a String, and perform a checksum operation on it, and if it differs you know there has been a change
or if you are deserialising the received JSON in Kotlin data classes, then out of the box, Kotlin will enable you to perform an equality operation on a previous copy of the data to know if there was a change.
This looks like an android app; if so, why don't you create a background service that makes requests to the API and updates the data as needed? You can use an AlarmManager class to set the interval threshold for polling by using the setInexactRepeating() method.
Most apps are updated in this fashion; sometimes, a separate table is created to catalog changesets.
Let me know if this helps.

Create a space with Google Chat REST API

We have a program that uses a service account to manage various thing inside Google Chat.
Now, we have the need to create a new space using the Google Chat REST API (spaces.create).
We already joined the developer preview program, as this endpoint is not yet generally available.
From what we understand, this endpoint is not possible to invoke via service account and so we wanted to ask you… can we invoke this endpoint automatically using “domain delegation”? If yes, how?
We always want to use the service account as it is not possible to show a login prompt to the user.
We enabled the domain delegation but that endpoint returns always status 403. (We are using Google.Apis library for .NET Core
using Google.Apis.Auth.OAuth2;
var credential = GoogleCredential.FromFile("key.json")
.CreateScoped("https://www.googleapis.com/auth/chat.spaces.create")
.CreateWithUser("service-account-email#project.iam.gserviceaccount.com");
var token = await credential.UnderlyingCredential.GetAccessTokenForRequestAsync();
HttpRequestMessage request = new(HttpMethod.Post, "https://chat.googleapis.com/v1/spaces");
request.Headers.Authorization = new("Bearer", token);
var payload = #"
{
""name"": ""testspace-1"",
""spaceType"": ""SPACE"",
""singleUserBotDm"": true,
""displayName"": ""Test Space""
}
";
request.Content = new StringContent(payload, System.Text.Encoding.UTF8, "application/json");
HttpClient client = new();
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
If you check the documentation Auth
You will notice it stats that service account authorization is supported. If you are part of thedeveloper preview program
The reason I asked about your code is that the last time i tried this which notably was a while ago. The google .net client library was not generated the methods that were under preview.
So while it may work yes. The issue your may have is that the client library when loaded will not have the method you need meaning you will have to code the call to the endpoint yourself.
If this is in fact the case let me know if you have any issues peceing it together I may be able to help.
update your code
There is an error in your code
.CreateWithUser("service-account-email#project.iam.gserviceaccount.com");
The email in CreateWithUser should be the user on your domain who you wish to delicate the service account as. Not the service account email address.

Call web service at alerting in grafana

I'm using Grafana and set an alert in a graph, How can I call an external API or web service when alert fired? thanks.
So the goal is to get information into an external service. I am making the assumption that your particular external api / web service is not in the list of supported notification channels.
Personally in this case, I would suggest using the webhook notification channel option, as it gives a TON of information to work through / interact with:
{
"dashboardId":1,
"evalMatches":[
{
"value":1,
"metric":"Count",
"tags":{
}
}
],
"imageUrl":"https://grafana.com/assets/img/blog/mixed_styles.png",
"message":"Notification Message",
"orgId":1,
"panelId":2,
"ruleId":1,
"ruleName":"Panel Title alert",
"ruleUrl":"http://localhost:3000/d/hZ7BuVbWz/test-dashboard?fullscreen\u0026edit\u0026tab=alert\u0026panelId=2\u0026orgId=1",
"state":"alerting",
"tags":{
"tag name":"tag value"
},
"title":"[Alerting] Panel Title alert"
}
This can be sent to any service that is capable of receiving webhooks and translating them into whatever you need for your external API endpoint, I might suggest the following:
integromat.com (Free account gives 1000 operations / month)
n8n.io (OSS and self-hosted but limited direct integration... does have HTTP, so you can use that to interact with whatever (including internal stuff)
Once in either of these tools, you build a webhook receiver and then a workflow that will translate the action into the formats needed by your external API / service.

Can we monitor for a particular text like (Name=abc) in API response and get notified in Postman?

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.

Publishing messages from Parse via PubNub

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.