getMe method

Future<TelegramClientLibraryTelegramLoginWidgetUser> getMe({
  1. Client? httpClient,
})

run executable telegram bot api

Implementation

Future<TelegramClientLibraryTelegramLoginWidgetUser> getMe({
  http.Client? httpClient,
}) async {
  httpClient ??= http_client;
  Map<String, String> headers = {
    // "Content-length": "69",
    "Content-Type": "application/x-www-form-urlencoded",
    "origin": "https://oauth.telegram.org",
    "User-Agent":
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
  };
  // Uri uri_api = Uri.parse("https://oauth.telegram.org").replace(
  //   pathSegments: [
  //     "auth",
  //     "get",
  //   ],
  //   queryParameters: {
  //     "bot_id": botId,
  //     "origin": botDomain,
  //     "request_access": "write",
  //     "embed": "1",
  //   },
  // );

  String ans = await session.get(
    url:
        "https://oauth.telegram.org/auth?bot_id=${botId}&origin=${botDomain}&embed=1",
    headers: headers,
    httpClient: httpClient,
  );
  Map userData = {"@type": "telegramClientLibraryTelegramLoginWidgetUser"};
  try {
    String id = ans.split('"id":')[1].split(',')[0];
    String firstName = ans.split('"first_name":"')[1].split('",')[0];
    String username = ans.split('"username":"')[1].split('",')[0];
    String hash = ans.split('"hash":"')[1].split('"')[0];
    userData["id"] = id;
    userData["first_name"] = firstName;
    userData["username"] = username;
    userData["hash"] = hash;
  } catch (e, stack) {
    userData["@type"] = "error";
    return TelegramClientLibraryTelegramLoginWidgetUser(userData);
  }
  userData["@type"] = "telegramClientLibraryTelegramLoginWidgetUser";
  return TelegramClientLibraryTelegramLoginWidgetUser(userData);
}