npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loopback-connector-seven

v1.0.0

Published

LoopBack connector for seven

Downloads

13

Readme

loopback-connector-seven

The official seven connector for LoopBack. Prior to using you will need to create an API key.

This connector supports the following endpoints of the seven REST API:

Installation

In your LoopBack project:

NPM

$ npm i loopback-connector-seven

Yarn

$ yarn add loopback-connector-seven

Setup

Create a data source

import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'
import {juggler} from '@loopback/repository'
import {SevenConnector} from 'loopback-connector-seven'

const config = {
    apiKey: process.env.SMS77_DUMMY_API_KEY,
    connector: SevenConnector,
    name: 'seven',
}

@lifeCycleObserver('datasource')
export class SevenDataSource extends juggler.DataSource implements LifeCycleObserver {
    static dataSourceName = 'seven'
    static readonly defaultConfig = config

    constructor(
        @inject('datasources.config.seven', {optional: true})
            dsConfig: object = config,
    ) {
        super('seven', dsConfig)
    }
}

Create a model

import {Model, model, property} from '@loopback/repository';

@model()
export class SevenMessage extends Model {
    @property({
        generated: false,
        id: true,
        required: true,
        type: 'string',
    })
    operation: 'voice' | 'sms';

    @property({
        required: true,
        type: 'string',
    })
    to: string;

    @property({
        required: false,
        type: 'string',
    })
    from: string;

    @property({
        required: true,
        type: 'string',
    })
    text: string;

    constructor(data?: Partial<SevenMessage>) {
        super(data);
    }
}

export interface SevenRelations {
    // describe navigational properties here
}

export type SevenWithRelations = SevenMessage & SevenRelations;

Create a service

import {injectable, BindingScope, Provider, inject} from '@loopback/core'
import {GenericService, getService} from '@loopback/service-proxy'
import {SevenDataSource} from '../datasources'
import {SevenMessage} from '../models'

export interface Seven extends GenericService {
    send(data: SevenMessage): Promise<unknown>;
}

@injectable({scope: BindingScope.TRANSIENT})
export class SevenProvider implements Provider<Seven> {
    constructor(
        @inject('datasources.seven')
        protected dataSource: SevenDataSource = new SevenDataSource(),
    ) {
    }

    value(): Promise<Seven> {
        return getService(this.dataSource)
    }
}

Usage

Send SMS

import {inject} from '@loopback/core'
import {post} from '@loopback/rest'
import {SevenMessage} from '../models'
import {Seven} from '../services'

export class SmsController {
    @post('/send-sms')
    async sms(
        @inject('services.Seven') sevenProvider: Seven,
    ): Promise<void> {
        const msg = new SevenMessage({
            from: 'optional sender ID',
            operation: 'sms',
            text: 'This is a test SMS from LoopBack via seven',
            to: 'phone number(s) for calling separated by comma',
        })

        try {
            const json = await sevenProvider.send(msg)
            console.log('json', json)
        } catch (e) {
            console.error('e', e)

            throw e
        }
    }
}

Make a text-to-speech call

import {inject} from '@loopback/core'
import {post} from '@loopback/rest'
import {SevenMessage} from '../models'
import {Seven} from '../services'

export class TextToSpeechController {
    @post('/send-voice')
    async voice(
        @inject('services.Seven') sevenProvider: Seven,
    ): Promise<void> {
        const msg = new SevenMessage({
            from: 'optional caller ID',
            operation: 'voice',
            text: 'This is a test call from LoopBack via seven',
            to: 'the number for calling',
        })

        try {
            const json = await sevenProvider.send(msg)
            console.log('json', json)
        } catch (e) {
            console.error('e', e)

            throw e
        }
    }
}

Options

Send SMS

{
    from: 'OPTIONAL_SENDER_ID',
    operation: 'sms',
    text: 'TEXT_MESSAGE',
    to: 'TARGET_PHONE_NUMBER(S)'
}

Make a text-to-speech call

{
    from: 'OPTIONAL_CALLER_ID',
    operation: 'call',
    text: 'TEXT_OR_XML',
    to: 'TARGET_PHONE_NUMBER'
}

Support

Need help? Feel free to contact us.

MIT