Send an alert notification from InfluxDb to Microsoft Teams - webhooks

I am running an influxDb, on my server, and I created below:
Notification Check
Notification Endpoint (HTTP POST)
Notification Rule
All above are running successfuly
I have also created a webhook connector to Microsoft teams in order for InfluxDb send the notification alert to it.
However, for the Microsoft Teams webhook to work successfully, needs a key called "summary" inside request body of the POST request.
InfluxDb has no key called summary in their request body. Something like this:
{
"summary":"text"
}
I am looking to find out how to alter the request body InfluxDb sends, however there is nothing on their documentation.
Any ideas ?

The incoming webhooks send messages as a card. So, the title and summary fields are mandatory. It is by design.

This might be late but I've created my own team connection task in influxdb, where I can add mentions and buttons.
Basic Example:
Copy teams into a task in influxdb and add this next code at the end.
This Example adds a mention for Tom Cruise with its respective teams ID ( use Graph Explorer to get the correct IDs). It's possible to add multiple mentions as follow:
mentions = addMention(name : "James Bond",id:"007") + addMention(name : "Tom Cruise",id:"123456")
Adding Button / Buttons
button = addButton(type: "Action.OpenUrl", title: "Go To Google.com", url:"google.com" )
button2 = addButton(type: "Action.OpenUrl", title: "Go To Mohameds GITHUB", url:"https://github.com/Mohamedkrs" )
url= "https://..."
endpoint1 = endpoint(url: url)
mentions = addMention(name : "James Bond",id:"007")
button = addButton(type: "Action.OpenUrl", title: "Go To Google.com", url:"google.com" )
button2 = addButton(type: "Action.OpenUrl", title: "Go To Mohameds GITHUB", url:"https://github.com/Mohamedkrs" )
crit_statuses =from(bucket: "bucket")
|> range(start: -15s)
|> filter(fn: (r) => r["_measurement"] == "win_cpu")
|> endpoint1(mapFn: (r) => ({
title: "Memory Usage",
text: "<at>team user name</at>: ${r.host}: Process uses ${r._value} GB",
summary: "Alert",
mention: mentions,
button : button + button1
}),
)()

Related

Make next input message part of callback_query function in Telegram Bot

I'm programming a Telegram Bot where it is shown to the user different options as inline buttons, one of them being "Search".
Once in search, I intend the next sent message to be the string to be used to search. However, I don't know how to make it so that the sent message is for the search query and not for other option/purposes.
If the bot file is read again from start every time a message or button is pressed, there is no way I can tell the bot that the next message is a message related to the pressed button (search) or a standard message not related to the pressed button (I don't know if I'm clear enough with my doubt or I'm making it more complicated to understand).
So relevant part of the code looks like this:
if(isset($request->callback_query->data)){
$data = $request->callback_query->data;
switch($data){
case 'search':
sendMessage($request->callback_query->message->chat->id, "Write what you want to search.");
//(HERE is where the program should "wait" for the user to input something to be used in a DB query)
//DBquery function
break;
}
}else{
keyboard($request->message->chat->id, "Choose one of the following options:", $keyboard);
}
$keyboard = array(
"inline_keyboard" => [
[
["text" => "\xF0\x9F\x94\x8E"." Search item","callback_data" => "search"],
["text" => "\xF0\x9F\x8C\x8F"." Visit web","url" => "https://website.com"]
//more options to be written
]
]
);

How to set dialogflow fulfillment response json context without using webhook client?

I want to create a rich response to Facebook integration using Dialogflow fulfillment. I tried using webhook but it's not working and then I try below way directly using response and now I am facing this context binding issue.
I tried below
let responseJson = {};
let rich = [
{
'text': {
'text': [
text
],
},
'platform': 'FACEBOOK'
},
];
responseJson.fulfillmentMessages = rich;
responseJson.outputContexts = context;
response.json(responseJson);
my context JSON
{ name: 'MAINTENANCE_REQUEST', lifespan: 5, parameters: { maintenanceRequest: maintenanceRequest }}
To add a custom payload without a webhook, go to your intent, and scroll to the bottom where it says "responses". Click on the plus sign (picture) and click on the facebook option. Click on the add responses -> custom payload. The format and available fields for the custom payload are described here. Delete the "Text Response" if it's there so the custom payload will be the only one to be returned.

Create a "dynamic" menu with Azure Chatbot

I am currently working with the MS chatbot on Azure, using node.js
I am at a point where I need to display a menu for the user, about different choices that may change from time to time.
I get the values through an API call and put them in a tab, then I create the menu and send it to the user. The problem is : I can't create a dynamic menu from my array
This is what I tried :
menu_choices = [x,y,z]
var menu = new builder.Message(session)
.text("This is the menu")
.suggestedActions(
builder.SuggestedActions.create(
session, [ function(){
menu_choices.forEach(function(choice){
builder.CardAction.imBack(session, "I want to select " + choice, choice)
})}
]));
session.send(menu);
It looks strange to use a function inside the SuggestedActions but I don't see how I can solve this, or even if it is possible or not.
Thanks and have a good day !
After working with the Microsoft support, we found the way (well mainly they haha) to do it :
array_Menu = [choice1,choice2,choice3]
var menu = new builder.Message(This is the menu :")
.suggestedActions(
builder.SuggestedActions.create(
session,
array_Menu.map(function(choice) {
return builder.CardAction.imBack(session, "This is a choice : " + choice, choice)
}
)
)
);
session.send(menu);

Facebook Messenger Extensions on Microsoft Edge -- GET parameters absent

I want to use Facebook Messenger Extensions (opening a Webview) with Microsoft Edge.
My app sends a request to the REST API endpoint messages. The payload is as follows. Documentation on this.
{
"messaging_type":"RESPONSE",
"recipient":{
"id":"<id>"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":"Test text",
"buttons":[
{
"type":"web_url",
"url":"https://c0292fc0.ngrok.io/facebook/render_multi_choice?data=24561",
"title":"Test Button",
"webview_height_ratio":"full",
"messenger_extensions":"true",
"fallback_url":"https://c0292fc0.ngrok.io/facebook/render_multi_choice?data=24561"
}
]
}
}
}
}
When the user taps the button "Test Button" in Messenger, a Webview pops up and displays the response at the fallback URL / URL : https://c0292fc0.ngrok.io/facebook/render_multi_choice?data=24561
Note the URL contains one parameter, data = 24561
My Python Flask App receives the request:
#application.route("/facebook/render_multi_choice", methods=["GET"])
def render_multi_choice():
args = request.args
print(args)
return "OK"
The issue is that one would expect args to be printed out as:
ImmutableMultiDict([('data', 24561), ('fb_iframe_origin', '')])
Yet, it is printed out as:
ImmutableMultiDict([('data', ''), ('fb_iframe_origin', '')])
My flow works fine in Google Chrome, but NOT on Microsoft Edge. Do you have any idea what the issue could be? If I open the URL directly in the browser (without the Webview), things work as expected on Edge.

Web push messaging.setBackgroundMessageHandler not working

I implemented web-push notifications on my site with Google Firebase service.
firebase.google.com/docs/cloud-messaging/js/client
I tested it and everything works fine, but when my website window isn't in focus (it's in background) or closed and if I get push-notification it will disappear after 20 seconds.
In my https://hdlava.me/j/firebase_subscribe.js file I added
requireInteraction: true
flag in messaging.onMessage so if I get push mesage when my website is open the message won't disappear until I click on it.
I tried to add this
requireInteraction: true
in messaging.setBackgroundMessageHandler in my https://hdlava.me/firebase-messaging-sw.js, but it's not working. Even:
console.log('[firebase-messaging-sw.js] Received background message ', payload)
doesn't work. It looks like whole messaging.setBackgroundMessageHandler does not work.
Can someone please help me figure out what is the problem ? Also if I use in firebase-messaging-sw.js
self.addEventListener("push",function(event)
instead messaging.setBackgroundMessageHandler so I have two messges at once. First message disappears and second one doesn't, but second one is not clickable. Is it possible to prevent first message and make second one to be clickable ?
Referring to the FCM docs:
https://firebase.google.com/docs/cloud-messaging/js/receive
"Note: If you set notification fields in your HTTP or XMPP send request, those values take precedence over any values specified in the service worker."
So, if you have
{
"notification": {
"title": "Your title",
"body": "Your message"
},
"to": "topic",
}
It never triggers the BackgroundMessageHandler. Because sending data this way, simply overrides your variables. If you want to trigger it you need to send your notification like this:
{
"data": {
"notification": {
"title": "Your title",
"body": "Your message"
}
},
"to": "topic",
}

Resources