How to use the thingpedia.Messaging function in thingpedia

To help you get started, we’ve selected a few thingpedia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stanford-oval / thingengine-core / lib / messaging / device_manager.js View on Github external
//
// Copyright 2015 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const events = require('events');
const Tp = require('thingpedia');

const DeviceView = require('../devices/device_view');

const MESSAGING_ACCOUNT_REGEX = /^([A-Za-z.0-9]+)-account:/;

class VirtualFeed extends Tp.Messaging.Feed {
    constructor(subfeeds) {
        const id = 'virtual:[' + subfeeds.map((f) => encodeURIComponent(f.feedId)).join(',') + ']';
        super(id);

        this._subfeeds = subfeeds;
    }

    getMembers() {
        const members = [];
        for (let f of this._subfeeds)
            members.push(...f.getMembers());
        return members;
    }

    _doOpen() {
        return Promise.all(this._subfeeds.map((f) => f.open()));
github stanford-oval / thingengine-core / lib / devices / builtins / omlet / omlet_messaging.js View on Github external
console.log('New message length ' + msg.Body.length);
        var body = JSON.parse(msg.Body);
        body.type = msg.Id.Type;
        body.serverTimestamp = t;
        body.sender = msg.Owner;
        body.msgId = client.store.getObjectId(receipt);

        var feedId = feed.identifier;
        if (this._messaging._feeds[feedId])
            this._messaging._feeds[feedId]._newMessage(body);

        this._messaging._newMessage(feed.identifier, body);
    }
}

module.exports = class Messaging extends Tp.Messaging {
    constructor(device) {
        super();
        this._device = device;
        this._device._chatObjectProcessor = new ChatObjectProcessor(this);
        this._feeds = {};
        this.client = null;
    }

    _newMessage(feedId, msg) {
        if (this.account !== msg.sender)
            this.emit('incoming-message', feedId, msg);
        else
            this.emit('outgoing-message', feedId, msg);
    }

    get account() {
github stanford-oval / thingpedia-common-devices / me.omlet.chat / omlet_messaging.js View on Github external
console.log('New message length ' + msg.Body.length);
        var body = JSON.parse(msg.Body);
        body.type = msg.Id.Type;
        body.serverTimestamp = t;
        body.sender = msg.Owner;
        body.msgId = client.store.getObjectId(receipt);

        var feedId = feed.identifier;
        if (this._messaging._feeds[feedId])
            this._messaging._feeds[feedId]._newMessage(body);

        this._messaging._newMessage(feed.identifier, body);
    }
}

module.exports = class Messaging extends Tp.Messaging {
    constructor(device) {
        super();
        this._device = device;
        this._device._chatObjectProcessor = new ChatObjectProcessor(this);
        this._feeds = {};
        this.client = null;
    }
    
    _newMessage(feedId, msg) {
        if (this.account !== msg.sender)
            this.emit('incoming-message', feedId, msg);
        else
            this.emit('outgoing-message', feedId, msg);
    }

    get type() {
github stanford-oval / almond-cloud / omlet / messaging.js View on Github external
}

    sendItem(item) {
        var silent = true;
        return Q.ninvoke(this._client._ldClient.messaging, '_sendObjToFeed', this._feed, 'text',
                         { text: JSON.stringify(item), silent: silent,
                           hidden: silent });
    }

    sendRaw(rawItem) {
        return Q.ninvoke(this._client._ldClient.messaging, '_sendObjToFeed', this._feed, rawItem.type,
                         rawItem);
    }
}

module.exports = class Messaging extends Tp.Messaging {
    constructor(client) {
        super();
        this.client = client;
        this._feeds = {};
    }

    get account() {
        return this.client.auth.getAccount();
    }

    _onFeedRemoved(o) {
        this.emit('feed-removed', o.identifier);
        delete this._feeds[o.identifier];
    }

    _onFeedChanged(o) {
github stanford-oval / thingengine-core / lib / devices / builtins / omlet / omlet_messaging.js View on Github external
return new Promise((callback, errback) => {
        args.push(callback);
        return object[method].apply(object, args);
    });
}

class OmletUser {
    constructor(id, o) {
        this.id = id;
        this.account = o.account;
        this.name = o.name;
        this.thumbnail = o.thumbnailHash;
    }
}

class OmletFeed extends Tp.Messaging.Feed {
    constructor(messaging, feedId) {
        super(feedId);

        this._messaging = messaging;
        this._device = messaging._device;
        this._insertListener = null;
        this._db = null;
        this.ownAccount = this._messaging.account;

        this._lastMessage = 0;
    }

    _newMessage(o) {
        if (o.serverTimestamp < this._lastMessage)
            return;
        this._lastMessage = o.serverTimestamp;
github stanford-oval / thingengine-core / lib / device-classes / omlet / omlet_messaging.js View on Github external
sendItem: function(item) {
        var silent = true;
        return Q.ninvoke(this._client.messaging, '_sendObjToFeed', this._feed, 'text',
                         { text: JSON.stringify(item), silent: silent,
                           hidden: silent });
    },

    sendRaw: function(rawItem) {
        return Q.ninvoke(this._client.messaging, '_sendObjToFeed', this._feed, rawItem.type,
                         rawItem);
    }
});

module.exports = new lang.Class({
    Name: 'OmletMessaging',
    Extends: Tp.Messaging,
    $rpcMethods: ['get isAvailable', 'getOwnId', 'getUserById', 'getAccountById',
                  'getFeedMetas', 'getFeedMeta'],

    _init: function(device) {
        this._device = device;

        this._feeds = {};
        this._syncclient = null;
    },

    _onFeedRemoved: function(o) {
        delete this._feeds[o.identifier];
    },

    _onFeedChanged: function(o) {
        var feed = this._feeds[o.identifier];
github stanford-oval / thingengine-core / lib / devices / builtins / matrix / matrix_messaging.js View on Github external
if (a[i] !== b[i])
            return false;
    }
    return true;
}


class MatrixUser {
    constructor(o) {
        this.account = 'matrix-account:' + o.user_id;
        this.name = o.display_name;
        this.thumbnail = o.avatar_url;
    }
}

class Feed extends Tp.Messaging.Feed {
    constructor(messaging, room) {
        super('matrix:' + room.roomId);

        this._roomId = room.roomId;
        this._messaging = messaging;
        this._device = messaging._device;
    }

    getMembers() {
        let members = [];
        let room = this._messaging.client.getRoom(this._roomId);
        for (let state of ['join', 'invite']) {
            for (let member of room.getMembersWithMembership(state))
                members.push('matrix-account:' + member.userId);
        }
        members.sort();
github stanford-oval / thingengine-core / lib / device-classes / omlet / omlet_messaging.js View on Github external
return object[method].apply(object, args);
    });
}

function arrayEqual(a, b) {
    if (a.length !== b.length)
        return false;
    for (var i = 0; i < a.length; i++)
        if (a[i] !== b[i])
            return false;
    return true;
}

const OmletFeed = new lang.Class({
    Name: 'OmletFeed',
    Extends: Tp.Messaging.Feed,

    _init: function(messaging, feedId) {
        this.parent(feedId);
        this._messaging = messaging;
        this._device = messaging._device;
        this._client = null;
        this._insertListener = null;
        this._db = null;
        this.ownId = null;

        this._memberList = [];
        this._members = [];
        this.name = null;
    },

    _onInsert: function(o) {
github stanford-oval / thingpedia-common-devices / me.omlet.chat / omlet_messaging.js View on Github external
return new Promise((callback, errback) => {
        args.push(callback);
        return object[method].apply(object, args);
    });
}

class OmletUser {
    constructor(id, o) {
        this.id = id;
        this.account = OMLET_ACCOUNT_PREFIX + o.account;
        this.name = o.name;
        this.thumbnail = o.thumbnailHash;
    }
}

class OmletFeed extends Tp.Messaging.Feed {
    constructor(messaging, feedId) {
        super('me.omlet.chat:' + feedId);

        this._omletFeedId = feedId;
        this._messaging = messaging;
        this._device = messaging._device;
        this._insertListener = null;
        this._db = null;
        this.ownAccount = this._messaging.account;

        this._lastMessage = 0;
    }

    _newMessage(o) {
        if (o.serverTimestamp < this._lastMessage)
            return;
github stanford-oval / thingengine-core / lib / devices / builtins / matrix / matrix_messaging.js View on Github external
onlyContentUri: true
        }));
    }

    sendPicture(url) {
        return this._getMxcUrl(url).then((url) => {
            return this._client.sendImageMessage(this._roomId, url, {}, 'image');
        });
    }

    sendItem(item) {
        return this._client.sendEvent(this._roomId, THINGPEDIA_EVENT_TYPE, item);
    }
}

module.exports = class MatrixMessaging extends Tp.Messaging {
    constructor(device) {
        super();
        this._device = device;
        this._feeds = new WeakMap;

        this.client = null;
        this._stopped = false;

        this._membershipListener = this._onMembership.bind(this);
        this._timelineListener = this._onTimeline.bind(this);
        this._nameListener = this._onName.bind(this);

        this._roomAliasCache = new Map;
    }

    _onName(room) {