How to use the messaging-api-common.camelcaseKeysDeep function in messaging-api-common

To help you get started, we’ve selected a few messaging-api-common 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 Yoctol / messaging-apis / packages / messaging-api-messenger / src / Messenger.ts View on Github external
function createMessage(
  payload: Types.Message,
  options: { quickReplies?: Types.QuickReply[] } = {}
): Types.Message {
  const message = {
    ...payload,
  };

  // snakecase support for backward compatibility
  const quickReplies = options.quickReplies || (options as any).quick_replies;

  if (quickReplies && Array.isArray(quickReplies) && quickReplies.length >= 1) {
    message.quickReplies = quickReplies;
  }

  return camelcaseKeysDeep(message);
}
github Yoctol / messaging-apis / packages / messaging-api-viber / src / ViberClient.ts View on Github external
async _callAPI(
    path: string,
    body: Record = {}
  ): Promise | never> {
    try {
      const response = await this._axios.post(
        path,

        // we can't apply a deep snake_case transform here
        // because it accept only PascalCase for keyboard and rich media
        snakecaseKeys(body, { deep: false })
      );

      const { config, request } = response;

      const data = (camelcaseKeysDeep(
        response.data
      ) as any) as Types.ResponseData;

      if (data.status !== 0) {
        throw new AxiosError(`Viber API - ${data.statusMessage}`, {
          config,
          request,
          response,
        });
      }

      return data;
    } catch (err) {
      throw new AxiosError(err.message, err);
    }
  }
github Yoctol / messaging-apis / packages / messaging-api-slack / src / SlackOAuthClient.ts View on Github external
async callMethod(
    method: Types.AvailableMethod,
    inputBody: Record = {}
  ): Promise {
    try {
      const body = {
        ...omit(inputBody, ['token', 'accessToken']),
        token: inputBody.accessToken || inputBody.token || this._token,
      };

      const response = await this._axios.post(
        method,
        querystring.stringify(snakecaseKeysDeep(body) as any)
      );

      const data = (camelcaseKeysDeep(
        response.data
      ) as any) as Types.OAuthAPIResponse;

      if (!data.ok) {
        const { config, request } = response;

        throw new AxiosError(`Slack API - ${data.error}`, {
          config,
          request,
          response,
        });
      }

      return data;
    } catch (err) {
      throw new AxiosError(err.message, err);
github Yoctol / messaging-apis / packages / messaging-api-telegram / src / TelegramClient.ts View on Github external
async _request(path: string, body: Record = {}) {
    try {
      const response = await this._axios.post(path, snakecaseKeysDeep(body));

      const { data, config, request } = response;

      if (!data.ok) {
        throw new AxiosError(`Telegram API - ${data.description || ''}`, {
          config,
          request,
          response,
        });
      }

      if (isPlainObject(data.result) || Array.isArray(data.result)) {
        return camelcaseKeysDeep(data.result);
      }
      return data.result;
    } catch (err) {
      if (err.response && err.response.data) {
        const { error_code, description } = err.response.data;
        const msg = `Telegram API - ${error_code} ${description || ''}`;

        throw new AxiosError(msg, err);
      }
      throw new AxiosError(err.message, err);
    }
  }
github Yoctol / messaging-apis / packages / messaging-api-messenger / src / MessengerClient.ts View on Github external
(item: { code: number; body: string }, index: number) => {
              const responseAccessPath = responseAccessPaths[index];
              const datum = camelcaseKeysDeep(item) as Record;
              if (responseAccessPath && datum.body) {
                return {
                  ...datum,
                  body: JSON.stringify(
                    get(
                      camelcaseKeysDeep(JSON.parse(datum.body)),
                      responseAccessPath
                    )
                  ),
                };
              }
              return datum;
            }
          ),
github Yoctol / messaging-apis / packages / messaging-api-messenger / src / MessengerClient.ts View on Github external
(data: any) =>
          data && isPlainObject(data) ? camelcaseKeysDeep(data) : data,
      ],
github Yoctol / bottender / packages / bottender / src / context / MessengerEvent.ts View on Github external
get gamePlay(): GamePlay | null {
    if (!this.isGamePlay) {
      return null;
    }

    const rawGamePlay = (this._rawEvent as any).gamePlay;

    let payload;
    try {
      const parsed = JSON.parse(rawGamePlay.payload);
      payload =
        parsed && typeof parsed === 'object'
          ? camelcaseKeysDeep(parsed)
          : parsed;
    } catch (e) {
      payload = rawGamePlay.payload;
    }

    return {
      ...rawGamePlay,
      payload,
    };
  }