summaryrefslogtreecommitdiffstats
path: root/bridge/msteams/handler.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-12-29 23:57:41 +0100
committerWim <wim@42.be>2020-03-01 22:19:33 +0100
commit8eb6ed563995d48e9835693d7a0af3155571113b (patch)
tree925eb77f9f5dd19e0d9a9e18adce4411f8f9f7a9 /bridge/msteams/handler.go
parent795a8705c3fdc5bf55e83d382e7d3ff233896a0b (diff)
downloadmatterbridge-msglm-8eb6ed563995d48e9835693d7a0af3155571113b.tar.gz
matterbridge-msglm-8eb6ed563995d48e9835693d7a0af3155571113b.tar.bz2
matterbridge-msglm-8eb6ed563995d48e9835693d7a0af3155571113b.zip
Support receiving attachments from msteams
Diffstat (limited to 'bridge/msteams/handler.go')
-rw-r--r--bridge/msteams/handler.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/bridge/msteams/handler.go b/bridge/msteams/handler.go
new file mode 100644
index 00000000..3283588a
--- /dev/null
+++ b/bridge/msteams/handler.go
@@ -0,0 +1,46 @@
+package bmsteams
+
+import (
+ "fmt"
+
+ "github.com/42wim/matterbridge/bridge/config"
+ "github.com/42wim/matterbridge/bridge/helper"
+)
+
+func (b *Bmsteams) findFile(weburl string) (string, error) {
+ itemRB, err := b.gc.GetDriveItemByURL(b.ctx, weburl)
+ if err != nil {
+ return "", err
+ }
+ itemRB.Workbook().Worksheets()
+ b.gc.Workbooks()
+ item, err := itemRB.Request().Get(b.ctx)
+ if err != nil {
+ return "", err
+ }
+ if url, ok := item.GetAdditionalData("@microsoft.graph.downloadUrl"); ok {
+ return url.(string), nil
+ }
+ return "", nil
+}
+
+// handleDownloadFile handles file download
+func (b *Bmsteams) handleDownloadFile(rmsg *config.Message, filename, weburl string) error {
+ realURL, err := b.findFile(weburl)
+ if err != nil {
+ return err
+ }
+ // Actually download the file.
+ data, err := helper.DownloadFile(realURL)
+ if err != nil {
+ return fmt.Errorf("download %s failed %#v", weburl, err)
+ }
+
+ // If a comment is attached to the file(s) it is in the 'Text' field of the teams messge event
+ // and should be added as comment to only one of the files. We reset the 'Text' field to ensure
+ // that the comment is not duplicated.
+ comment := rmsg.Text
+ rmsg.Text = ""
+ helper.HandleDownloadData(b.Log, rmsg, filename, comment, weburl, data, b.General)
+ return nil
+}