0.0.6 • Published 6 months ago

nestjs-amo v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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.

0.0.5

8 months ago

0.0.6

6 months ago

0.0.3

8 months ago

0.0.4

8 months ago

0.0.2

9 months ago

0.0.1

9 months ago

0.0.0

9 months ago