Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. powo01

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    P
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 1
    • Groups 0

    powo01

    @powo01

    1
    Reputation
    5
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    powo01 Follow

    Best posts made by powo01

    • einfacher Matrix Chat Client

      Hallo,

      ich habe mit Hilfe der "matrix-js-sdk" ein einfaches Typescript erstellt was Nachrichten in einen Raum
      innerhalb des matrix.org Netzwerk schicken

      namespace matrixClient {
          const matrixJsSdk = require('matrix-js-sdk')
          
          const configPrefix:string = '0_userdata.0.matrix'
          const serverUrl:string = getState(configPrefix + 'Url'/*matrixUrl*/).val
          const testRoomId:string = getState(configPrefix + 'Room'/*matrixRoom*/).val
          const loginData:object = JSON.parse(getState(configPrefix + 'Login'/*matrixLogin*/).val)
          
          const matrixMessage: string = 'matrixMessage'
          const eventType:string = 'm.room.message'
          const messageType:string = 'm.text'
      
          const matrixClient = matrixJsSdk.createClient(serverUrl)
      
          const eventReceiverCallback = function(event, room, toStartOfTimeline):void {
              if (event.getType() != eventType &&
                  event.getRoomId() != testRoomId &&
                  event.getContent().msgtype != messageType) {
                  return;
              }
      
              log(event.getContent().body)
          }
      
          const sendMessageToMatrix = function (data: string): any {
              const content: object = {
                  "msgtype": messageType,
                  "body": data
              }
      
              matrixClient.sendEvent(testRoomId, eventType, content, "").then((res) => {
              }).catch((err) => {
                  log(err)
              })
      
              
              return(Date.now())
          }
      
          onStop(() => {
              onMessageUnregister(matrixMessage)
              matrixClient.stopClient()
              matrixClient.logout()
          })
      
          matrixClient.login("m.login.password", loginData).then((response) => {
              // matrixClient.initCrypto()
              matrixClient.startClient()
      
              matrixClient.once('sync', function (state, prevState, res) {
                  console.log(state) // state will be 'PREPARED' when the client is ready to use
      
                  matrixClient.on("Room.timeline", eventReceiverCallback)
                  onMessage(matrixMessage, sendMessageToMatrix)
              })
          })
      }
      

      zum Senden über diesen Client benutze ich die folgende Funktion, die bei mir in global liegt und damit allen scripts zur Verfügung steht

      /**
       * send message to matrix messager
       * 
       * @param message Message to send
       */
      const sendMessageToMatrix = function(message:string, prefix:string = scriptName + ": ") {
          if(isScriptActive('script.js.test.matrix-client')) {
              messageTo('matrixMessage', prefix + message)
          }
      }
      

      Vielleicht kann jemand etwas damit angefangen

      VG,
      powo01

      posted in JavaScript
      P
      powo01

    Latest posts made by powo01

    • einfacher Matrix Chat Client

      Hallo,

      ich habe mit Hilfe der "matrix-js-sdk" ein einfaches Typescript erstellt was Nachrichten in einen Raum
      innerhalb des matrix.org Netzwerk schicken

      namespace matrixClient {
          const matrixJsSdk = require('matrix-js-sdk')
          
          const configPrefix:string = '0_userdata.0.matrix'
          const serverUrl:string = getState(configPrefix + 'Url'/*matrixUrl*/).val
          const testRoomId:string = getState(configPrefix + 'Room'/*matrixRoom*/).val
          const loginData:object = JSON.parse(getState(configPrefix + 'Login'/*matrixLogin*/).val)
          
          const matrixMessage: string = 'matrixMessage'
          const eventType:string = 'm.room.message'
          const messageType:string = 'm.text'
      
          const matrixClient = matrixJsSdk.createClient(serverUrl)
      
          const eventReceiverCallback = function(event, room, toStartOfTimeline):void {
              if (event.getType() != eventType &&
                  event.getRoomId() != testRoomId &&
                  event.getContent().msgtype != messageType) {
                  return;
              }
      
              log(event.getContent().body)
          }
      
          const sendMessageToMatrix = function (data: string): any {
              const content: object = {
                  "msgtype": messageType,
                  "body": data
              }
      
              matrixClient.sendEvent(testRoomId, eventType, content, "").then((res) => {
              }).catch((err) => {
                  log(err)
              })
      
              
              return(Date.now())
          }
      
          onStop(() => {
              onMessageUnregister(matrixMessage)
              matrixClient.stopClient()
              matrixClient.logout()
          })
      
          matrixClient.login("m.login.password", loginData).then((response) => {
              // matrixClient.initCrypto()
              matrixClient.startClient()
      
              matrixClient.once('sync', function (state, prevState, res) {
                  console.log(state) // state will be 'PREPARED' when the client is ready to use
      
                  matrixClient.on("Room.timeline", eventReceiverCallback)
                  onMessage(matrixMessage, sendMessageToMatrix)
              })
          })
      }
      

      zum Senden über diesen Client benutze ich die folgende Funktion, die bei mir in global liegt und damit allen scripts zur Verfügung steht

      /**
       * send message to matrix messager
       * 
       * @param message Message to send
       */
      const sendMessageToMatrix = function(message:string, prefix:string = scriptName + ": ") {
          if(isScriptActive('script.js.test.matrix-client')) {
              messageTo('matrixMessage', prefix + message)
          }
      }
      

      Vielleicht kann jemand etwas damit angefangen

      VG,
      powo01

      posted in JavaScript
      P
      powo01
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
    The ioBroker Community 2014-2023
    logo