(11.12.2020, 15:38)Thomas Wrote: Hi
Is there anybody who tried integrate LM to MS Teams environment? Directly, through an app, MQTT, IFTTT etc?
I remember there have been requests about Telegram integration and I would like to use it in similar way but in a corporate environment. My idea is a chat for every office and a chatbot answering commands like "turn lights on" etc.
Hi Thomas,
I found this solution to do this
In my case I need to obtain values from my objects and send this values based on events and schedule automaticaly to MS graph and insert into a SharePoint list.
This is usefull for send notifications to telegram or insert into MS enviroment all based on events
1st of all you need to create an app in your azure enviroment and get your token id and secret, then you need to set permissions to this app (read, write, send teams...) when you have this you can go to exec this functions
-obtain MS graph token
Code:
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
--variables
clientID = 'xxxxxxxxx'
tenantName = 'xxxxxx.onmicrosoft.com'
clientSecret = 'xxxxxxxxx'
url_token = "https://login.microsoftonline.com/".. tostring(tenantName) .. "/oauth2/v2.0/token"
--componer peticion token
ReqTokenBody = "client_id=" .. clientID .. "&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret=" .. clientSecret .. "&grant_type=client_credentials"
function GetTokenMSGraph()
local response_body = {}
local export_data = {}
res, code = https.request({
url = url_token,
method = 'POST',
protocol = 'tlsv12',
headers = {
['Content-Type'] = 'application/x-www-form-urlencoded';
['Content-Length'] = #ReqTokenBody;
['Host'] = 'login.microsoftonline.com';
};
source = ltn12.source.string(ReqTokenBody);
sink = ltn12.sink.table(response_body);
})
--log(res, code)
if code == 200 then
response_decode = json.decode(table.concat(response_body))
--log(response_decode)
token = response_decode["access_token"]
--log(token)
return token
end
end
you can store this token in a variable:
tokenMSgraph = GetTokenMSGraph()
and now when you have this ms graph token you can obtain a value that you need and send it to where you want on microsoft enviroment, this function is only for insert this values into a sharepoint list, if you want to send to teams you need to change the url variable for the correct url, you can check this here
https://developer.microsoft.com/en-us/gr...h-explorer
-insert values into Sharepoint list
Code:
function WiserKNX(value)
local response_body = {}
--log(tokenMSgraph)
log(value)
time = os.date('%Y-%m-%d %H:%M:%S', os.time())
title = 'Tienda CO2'
url = "https://graph.microsoft.com/v1.0/groups/xxxxxxxxx/sites/root/lists/xxxxxx/items"
insert = "{ 'fields': {'Title': '".. title .."' ,'value': '"..value.."','tiempo': '"..time.."'}}"
log(insert)
res, code = https.request({
url = url,
method = 'POST',
protocol = 'tlsv12',
headers = {
['authorization'] = 'Bearer ' .. tokenMSgraph,
['content-type'] = 'application/json',
['content-length'] = #insert,
};
source = ltn12.source.string(insert);
sink = ltn12.sink.table(response_body);
})
log(res, code)
end
--read value from KNX
read = grp.getvalue('x/x/x')
WiserKNX(read)
I thinks this works for your idea