Skip to content

Add Chat API support #25

@belyaev-dev

Description

@belyaev-dev

We need to update requests module so we can add Chats API support. Currently it's not possible even using raw amoCRM API requests.

Docs: amoCRM and Kommo

Required methods:

  • Connect channel
  • Disconnect channel
  • Create chat
  • Link chat to contact (update contact entity)
  • Send message (incoming/outgoing)
  • Get chat history
  • Update delivery status
  • Typing infomation
  • Send reaction
  • Withdraw reaction

Required webhooks:

  • Outgoing message webhook

Required integration tokens, received from amoCRM when registering new Chats API integration:

  1. AMOJO_UUID
  2. AMOJO_BOT_UUID
  3. AMOJO_SECRET

Required account data:

  1. ACCOUNT_AMOJO_ID (received by /api/v4/account?with=amojo_id req)
  2. SCOPE_ID (consists of ${AMOJO_UUID}_${ACCOUNT_AMOJO_ID})

We also need to constuct complex headers using request body to work with chats API, example:

import { createHash } from "https://deno.land/std@0.91.0/hash/mod.ts";
import { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts";

private getHeaders(body: object): Headers {
    const contentType = "application/json";
    const date = new Date().toUTCString().replace(
      /(\w+), (\d+) (\w+) (\d+) (\d+):(\d+):(\d+) GMT/,
      "$1, $2 $3 $4 $5:$6:$7 +0000",
    );
    const requestBody = JSON.stringify(body);
    const checkSum = createHash("md5").update(requestBody).toString("hex");

    const signature = hmac("sha1", AMOJO_SECRET, requestBody, "utf8", "hex").toString();

    const headers = new Headers();
    headers.append("Date", date);
    headers.append("Content-Type", contentType);
    headers.append("Content-MD5", checkSum);
    headers.append("X-Signature", signature);

    return headers;
  }

Any help is appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions