This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

MS Teams integration
#1
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.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#2
Have you seen their API documentation? https://docs.microsoft.com/en-us/graph/a...&tabs=http
Reply
#3
(17.12.2020, 08:55)admin Wrote: Have you seen their API documentation? https://docs.microsoft.com/en-us/graph/a...&tabs=http
No, I still hope there's a ready to use solution (through IFTTT, Azure IoT etc) somewhere. But thank you for the link, I'm afraid it will be useful in the future.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#4
(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 Smile

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
Reply
#5
Seeing the success we are going to have with Telegram here in Spain, are these scripts the same system as Telegram? Place the first one in the library and let me know how they are placed in an event?
Thanks
Reply
#6
The initial setup is a lot more complicated. You need to create an App on MS side to acquire an access token. The use HTTP requests to send messages to a specific channel: https://learn.microsoft.com/en-us/graph/...p#examples
Reply
#7
Hello, I created a bot in MS, I have all the data and permissions, is there any lua example to integrate that data and proceed to send notices?

Thank you
Reply
#8
We don't have any ready-made examples for this.

You can check the official documentation:
https://learn.microsoft.com/en-us/azure/...ervice-4.0
https://learn.microsoft.com/en-us/azure/...ervice-4.0
Reply
#9
Code:
require('ssl.https')
require('json')

local token = 'TU_TOKEN_DE_ACCESO'  -- Token de acceso de la aplicación en Microsoft
local team_id = 'ID_DEL_EQUIPO'
local channel_id = 'ID_DEL_CANAL'

-----------------------------------------------------------------------------------------

function send_message(message)
  local url = 'https://graph.microsoft.com/v1.0/teams/' .. team_id .. '/channels/' .. channel_id .. '/messages'
  local message_data = { body = { content = message } }
  local json_data = json.encode(message_data)
  local headers = {
    ["Authorization"] = "Bearer " .. token,
    ["Content-Type"] = "application/json",
    ["Content-Length"] = tostring(#json_data)
  }
  return https.request(url, {
    method = "POST",
    headers = headers,
    source = ltn12.source.string(json_data)
  })
end

 Hello, would it be something like that?
Reply
#10
If it does not work then log what is returned by the HTTP request. You might also need to request a new token periodically as it has a limited lifetime. You can either do it before each request or via a scheduled script and save token into storage then use it in sending scripts.
Reply


Forum Jump: