Logic Machine Forum
MS Teams integration - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: MS Teams integration (/showthread.php?tid=3059)



MS Teams integration - Thomas - 11.12.2020

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.


RE: MS Teams integration - admin - 17.12.2020

Have you seen their API documentation? https://docs.microsoft.com/en-us/graph/api/chat-list-message?view=graph-rest-beta&tabs=http


RE: MS Teams integration - Thomas - 17.12.2020

(17.12.2020, 08:55)admin Wrote: Have you seen their API documentation? https://docs.microsoft.com/en-us/graph/api/chat-list-message?view=graph-rest-beta&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.


RE: MS Teams integration - maavcrusoe - 15.10.2021

(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/graph/graph-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


RE: MS Teams integration - nmedalacabeza - 24.03.2024

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


RE: MS Teams integration - admin - 25.03.2024

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/api/channel-post-messages?view=graph-rest-1.0&tabs=http#examples


RE: MS Teams integration - nmedalacabeza - 26.03.2024

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


RE: MS Teams integration - admin - 26.03.2024

We don't have any ready-made examples for this.

You can check the official documentation:
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-quickstart?view=azure-bot-service-4.0
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0