nestjs-amo
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

NestJS AmoCRM

NPM Version Package License NPM Downloads

Introduction

This is a simple wrapper of Amo libruary. With this module you can interacting with the amoCRM/Kommo API from a NestJS application.

Installation

yarn add nestjs-amo

Usage

Importing module Async

import { MailgunModule } from 'nestjs-mailgun';
@Module({
  imports: [
    MailgunModule.forAsyncRoot({
      useFactory: async () => {
				return {
					widget_settings: {
						client_id: '1111-1111-1111-1111', // From widget settings
						client_secret: 'secret from amoCRM settings', // From widget settings
						redirect_uri: 'https://example.ru', // From widget settings
					},
					getCredentials: (amoId) => {
						// Implement your logic to retrieve a token from your long-term storage facility
						return {
							access_token: 'some token',
							expires_at: 86400,
							expires_in: 1693211983,
							refresh_token: 'saved token',
							domain: 'https://example.ru',
						};
					},
					onTokenUpdate: async (amoId, token) => {
						// Implement your logic for saving authorization keys to long-term storage
						console.log(token);
					},
				};
      },
			// Here you can import the desired module to use it in the 
			// useFactory function to retrieve or update data from long-term storage
			imports: [], 
      inject: []
    }),
  ],
  providers: [],
  exports: [],
})
export class YourModule {}

Calling Send Method

import { AmoService } from 'nestjs-amo-api';

@Injectable()
export class YourService {
  constructor(private amoService: AmoService) {}

	async method() {
		const amoApi = await this.amoService.create(123);
    return amoApi.account.getAccount({ with: ['version'] });
	}
}

Calling Custom endpoint

import { AmoService } from 'nestjs-amo-api';

@Injectable()
export class YourService {
  constructor(private amoService: AmoService) {}

	async method() {
		const amoApi = await this.amoService.create(123);
    return amoApi.raw.get({
      url: '/ajax/merge/leads/save',
      headers: {
        'X-Requested-With': 'XMLHttpRequest',
      },
      payload: 'some payload',
    });
	}
}

Contributing

Contributions welcome! See Contributing.

Notes

This project is not endorsed by or affiliated with AmoCRM.

Author

Yaroslav Tolstoy Site

License

Licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i nestjs-amo

Weekly Downloads

3

Version

0.0.6

License

MIT

Unpacked Size

18.1 kB

Total Files

20

Last publish

Collaborators

  • yatolstoy