How to send a push notification in unificationengine - unificationengine

How to send a push notification to a channel in unificationengine?
If a user is already created the channel via UE.

Example for pushing messages to UE
curl -XPOST https://apiv2.unificationengine.com/v2/push/notification -u CONNECTOR_KEY:CONNECTOR_SECRET –data “{ \"channel\”: \“6d2d2111-d3b6-4ac9-8e67-55980a141fdd_sms\”, \“data\”: \“test message\”}“ -k
The documentation for push messages is given in Connector section in https://developer.unificationengine.com.

Related

Schedule completed event is not supported by stripe

I am using stripe schedules to handle the downgrade of the subscriptions. I need to test it, however, the events subscription_schedule.completed is not supported by stripe CLI(Even I upgraded to latest verison).
Theres no way on stripe dashboard to compelte the schedule before time.I need to do handle stuff on my backend after this event is triggered, what should I do?
subscription_schedule.completed events are sent when a Subscription Schedule transitions to having a status of completed. This happens when the Schedule has end_behavior: cancel and was allowed to end naturally by completing its last phase (not through an API call to cancel it).
You can trigger subscription_schedule.completed events yourself by updating or creating a new Subscription Schedule that ends a few seconds in the future and has end_behavior: cancel. Here's an example of how you would do this using curl (replacing FUTURE_TIMESTAMP with one that is a few seconds in the future, and using your own keys and object IDs):
curl https://api.stripe.com/v1/subscription_schedules \
-u sk_test_XXX: \
-d customer=cus_XXX \
-d start_date=now \
-d end_behavior=cancel \
-d "phases[0][items][0][price]"=price_XXX \
-d "phases[0][items][0][quantity]"=1 \
-d "phases[0][end_date]"={{FUTURE_TIMESTAMP}}

Can't do GET request for pull subscription from local fake PubSub Server

TL;DR: What is the correct way to send a GET Request to do a pull subscription from a Pub/Sub server. What is the correct URL to use?
I am running a local Google Pub/Sub fake using gcloud beta emulators pubsub start, I have been able to successfully publish to it using a ruby script I wrote, however I have been unable to do a pull subscription.
I am aiming to accomplish this just using a GET request, not a script. One of the issues I've found is there's tons of documentation on doing pull subscriptions with a client or gcloud, but very little on how to access the server by URL. Perhaps I am misunderstanding what is possible - but I want to publish a message to pub/sub using a ruby client, and then use Postman to do a GET request to the pub/sub server to retrieve the message.
I am fairly certain the issue is with how I am making a get request, but I have reproduced everything else below for context
Ruby Publishing Code
require "google/cloud/pubsub"
require 'json'
class Publisher
def publish(event)
puts "1==============>>>>>>>> publishing..."
pubsub = Google::Cloud::PubSub.new(
project_id: "grpc-demo-proj",
emulator_host: "localhost:8085"
)
topic_id = "event_topic"
topic = pubsub.topic topic_id
begin
topic.publish_async "receive_event#event",
event: JSON.generate(event) do |result|
raise "Failed to publish the message." unless result.succeeded?
puts "2==============>>>>>>>> Message published asynchronously."
end
# Stop the async_publisher to send all queued messages immediately.
topic.async_publisher.stop.wait!
rescue StandardError => e
puts "3==============>>>>>>>> Received error while publishing: #{e.message}"
end
end
end
This seems to work, as I get
1==============>>>>>>>> publishing...
DEBUG GRPC : calling localhost:8085:/google.pubsub.v1.Publisher/GetTopic
DEBUG GRPC : calling localhost:8085:/google.pubsub.v1.Publisher/Publish
2==============>>>>>>>> Message published asynchronously.
In my terminal.
I also have the Pub/Sub server running using the following shell scripts.
#!/bin/bash
# Kill the existing process if it's already running
if [ "$(lsof -i:8085)" ]; then
kill $(lsof -t -i:8085)
fi
# Kick off the new process
gcloud beta emulators pubsub start --project=grpc-demo-proj
# Connect to environment variables
$(gcloud beta emulators pubsub env-init)
PubSub Setup Script
#!/bin/bash
# Wait for the pubsub emulator to boot up
sleep 7
while [[ ! "$(lsof -i:8085)" ]]
do
echo '#===> PUBSUB EMULATOR SETUP: Waiting for PubSub Emulator to start...'
sleep 3
done
# Create topics
curl --header "Content-Type: application/json" \
--request PUT \
http://localhost:8085/v1/projects/grpc-demo-proj/topics/event_topic
# Create test subscriptions for each topic
curl --header "Content-Type: application/json" \
--request PUT \
--data '{"topic": "projects/grpc-demo-proj/topics/event_topic"}' \
http://localhost:8085/v1/projects/grpc-demo-proj/subscriptions/event_topic.test_sub1
Again. These seem to work well.
Where I have trouble...
is doing a pull subscription from the pub/sub server using a GET request (Either from PostMan, or just in browser's URL bar)
http://localhost:8085/v1/projects/grpc-demo-proj/subscriptions/event_topic.test_sub1:pull
Returns
{
"error": {
"code": 400,
"message": "Invalid [subscriptions] name: (name=projects/grpc-demo-proj/subscriptions/event_topic.test_sub1:pull)",
"status": "INVALID_ARGUMENT"
}
}
But the subscription name is valid, as
http://localhost:8085/v1/projects/grpc-demo-proj/subscriptions/event_topic.test_sub1
returns
{
"name": "projects/grpc-demo-proj/subscriptions/event_topic.test_sub1",
"topic": "projects/grpc-demo-proj/topics/event_topic",
"pushConfig": {},
"ackDeadlineSeconds": 10,
"messageRetentionDuration": "604800s"
}
Which would seem to confirm the server is working, and the topics and subscriptions have been successfully created.
Although -NOT- the solution I am looking for, I tried using gcloud in command line:
bgc#jadzia:~$ gcloud beta pubsub subscriptions pull test_sub1
ERROR: (gcloud.beta.pubsub.subscriptions.pull) NOT_FOUND: Resource not found (resource=test_sub1).
Even though other sources seem to confirm this subscription does exist.
While it could possibly be an issue with Ruby incorrectly saying it successfully published the message, or something is wrong with the server. I suspect I'm just not doing the GET request correctly. I've tried several variations on the above GET request but won't list them all here.
So, without using a script - how can I get a message back from the pub/sub server? Ideally a URL for a GET request I can plug into PostMan, but command-line based solutions may also work here.
I did reproduce your local fake Pub/sub server using the all the scripts you posted. As you commented I used POST instead of GET and got a response. Pub/Sub subscriptions pull reference
POST https://pubsub.googleapis.com/v1/{subscription}:pull
POST request for subscriptions pull:
curl --header "Content-Type: application/json" \
--request POST \
--data "{
"maxMessages": "1"
}" \
http://localhost:8085/v1/projects/my-project/subscriptions/event_topic.test_sub1:pull
Output of subscriptions pull:
Pubsub Message is encoded in base 64. Take note that I ran everything (creation of pubsub server, topics, subscriber, publish of message, pulling of message) in the Google cloud shell.
EDIT 1:
As Brian mentioned, this is the request that is working for him. This works on my testing as well!
curl --header "Content-Type: application/json" \
--request POST \
localhost:8085/v1/projects/my-prject/subscriptions/event_topic.test_sub1:pull?maxMessages=5
Output:

Why my Email to SMS messaging not going through using Nagios Core custom test

I would like to send SMS notifications to my phone when a host is unreachable using Nagios Core. I already have Nagios configured and being monitored. Also, I have the contacts.cfg and commands.cfg files already added. I am using email to sms to send messages. For example: 8041233456#tmomail.net. I am using Redhat Linux and I already used the command definition in the Linux command to see if I am able to get sms messaging and it worked. For example: adding the "command_line" that is initialized below in the Linux command I actually receive a message and only see $ as an output, but at least is went through.
My issue is when going to Nagios core and selecting the custom host test to send I receive no response. This custom test does work with regular email though. Below are my config files that I added.
define contact {
contact_name ericg-cell
use generic-contact
alias my name
email 8041233456#tmomail.net
service_notification_commands notify-service-by-email
host_notification_commands notify-service-by-email
service_notifications_enabled 1
#service_notification_options u
}
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n $NOTIFICATIONCOMMENT$\n" | /bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
I want to stay using mailx to send sms messaging and not any other tools related because I see online that there are only showing other tools to use and not mailx. I also already have my services and host files already being monitored.
You can use https://d7networks.com Nagios plugin for implementing the SMS service. Its easy to configure and SMS feature can be obtained on real time.
please refer https://exchange.nagios.org/directory/Addons/Notifications/SMS/D7SMS-for-Nagios/details

Send MQTT message from the android client to all the clients through MQTT broker

I need MQTT broker to publish the received MQTT message from the Android client to all other clients so added mosquitto pub command in the body of the message.
publish(client,"mosquitto_pub -h 192.34.63.138 -t fromApp -m "Turn" -d ");
It is giving error that "Can't resolve symbol "Turn" and ; or ) expected" .
Update
I understood it correctly later. I actually needed an MQTT message from the android client to be sent to all other clients so I thought to include publish keyword in the message body which was quite wrong. The MQTT itself sends the received messages to all the clients provided if the clients have subscribed to that topic.Hopefully, it will help other readers.
There are a number of problems with your approach.
First, the compile time error is because you have nested " within a String (which is bound by ". To do this you need to escape the "'s with the \ as follows:
"mosquitto_pub -h 192.34.63.138 -t fromApp -m \"Turn\" -d "
The second problem is the more important one. MQTT doesn't work the way you seem to be expecting it to.
You do not send commands to the broker for it to execute, you publish a message from one client to a topic, and the broker then delivers that message to all the clients that have subscribed to that topic. So in this case you would just publish a message with the payload Turn to the topic fromApp. Which is going to look something like:
MqttMessage message = new MqttMessage("Turn".getBytes());
sampleClient.publish("fromApp", message);

How to send a single message to multi connections using UE?

I have tried to send messages to various connections via unification engine and it works fine. It's mentioned here (https://developer.unificationengine.com/) that its possible to send only one message to unification engine mentioning various connections and it sends it to respective social media apps. However, I am not able to find a way to get it to work. Please advise if anyone has tried.
Appreciate your help!
Thanks & Best Regards,
Anand Patil
It is possible to send same message to multiple connections via unification engine.
The following command will send the same messsage to two facebook connections and a twitter connection
curl -XPOST https://apiv2.unificationengine.com/v2/message/send --data "{ \"message\": {
\"receivers\": [
{\"name\": \"Me\", \"address\": \"\" , \"Connector\": \"UNIQUE_CONNECTION_IDENTIFIER_FACEBOOK_1\"},
{\"name\": \"Me\", \"address\": \"\" , \"Connector\": \"UNIQUE_CONNECTION_IDENTIFIER_FACEBOOK_2\"},
{\"name\": \"name\", \"address\": \"TWITTER_HANDLE\" , \"Connector\": \"UNIQUE_CONNECTION_IDENTIFIER_TWITTER_1\"}
],
\"parts\":
[{\"id\": \"1\",\"contentType\": \"text/plain\", \"data\":\"MESSAGE_BODY\" ,\"size\": MESSAGE_BODY_SIZE,\"type\": \"body\",\"sort\":0}]
}}" -u USER_ACCESSKEY:USER_ACCESSSECRET -k

Resources