Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react native support #1112

Open
ajai06 opened this issue Jun 26, 2020 · 23 comments
Open

react native support #1112

ajai06 opened this issue Jun 26, 2020 · 23 comments

Comments

@ajai06
Copy link

ajai06 commented Jun 26, 2020

is there any support or package for react-native ?

@levlam
Copy link
Contributor

levlam commented Jun 26, 2020

You can build TDLib for any platform that is supported by React Native. You need just to load and use the prebuilt shared library in React Native project.

@ajai06
Copy link
Author

ajai06 commented Jun 26, 2020

not seeing anything that is supporting for react-native

@levlam
Copy link
Contributor

levlam commented Jun 26, 2020

You need to just wrap TDLib JSON interface, containing only 5 methods in pure C, using Native module: https://reactnative.dev/docs/native-modules-android.html.

@Ilya93
Copy link

Ilya93 commented Jul 15, 2020

You need to just wrap TDLib JSON interface, containing only 5 methods in pure C, using Native module: https://reactnative.dev/docs/native-modules-android.html.

Sorry for silly question. What exactly I need to wrap ?

@levlam
Copy link
Contributor

levlam commented Jul 15, 2020

@vidit-bhatia
Copy link

@ajai06 reach out to me I have a full fledged react native component working for both android and ios

@AndrewEyesman
Copy link

I'm also looking to build a react-native app using the telegram API, though I'm having trouble finding many resources for help. I've successfully built tdlib for node.js, but I'm unsure what to do from here. I'm still fairly new to this stuff, so if anyone has any tips id greatly appreciate it!

@jumoog
Copy link

jumoog commented Feb 3, 2021

if you want to work with nodejs i can recommend you to use https://github.com/airgram/airgram.

@AndrewEyesman
Copy link

AndrewEyesman commented Feb 3, 2021

Thanks for the response @jumoog,

I'm actually already using Airgram, but I can't figure out how to integrate it with my react-native project. This is what I have so far:

const airgram = new Airgram({
    apiId: API_ID,
    apiHash: API_HASH',
    command: '../tdlib/bin/tdjson.dll',
    logVerbosityLevel: 1,
});

airgram.use(
    new Auth({
        code: () => prompt(`Please enter the secret code:\n`),
        phoneNumber: () => prompt(`Please enter your phone number:\n`),
    })
);

I can log in with my telegram account and make API calls, but I don't know where to begin with react-native. My understanding of node and server-side programming is quite limited, so I'm really lost at this point. Am I supposed to create and express server and make calls to my API instance? How would I get real-time updates to my react-native app? I have too many questions and barely any answers, I can hardly find anything online. If you have any additional information please let me know, thanks!

@oscar-rey-mosquera
Copy link

oscar-rey-mosquera commented Feb 20, 2021

hello @AndrewEyesman, how have you made airgram js work for you? I passed the tdlib folder to my node project and entered the path in
command tdlib / bin / tdjson.dll and I get an error if you could explain me

C:\Users\Oscar Humberto\Desktop\javascript\telenode\node_modules\airgram\node_modules\ffi-napi\lib\dynamic_library.js:75
throw new Error('Dynamic Linking Error: ' + err);
^

Error: Dynamic Linking Error: Win32 error 126
at new DynamicLibrary (C:\Users\Oscar Humberto\Desktop\javascript\telenode\node_modules\airgram\node_modules\ffi-napi\lib\dynamic_library.js:75:11)
at Object.Library (C:\Users\Oscar Humberto\Desktop\javascript\telenode\node_modules\airgram\node_modules\ffi-napi\lib\library.js:47:10)
at new TdJsonClient (C:\Users\Oscar Humberto\Desktop\javascript\telenode\node_modules\airgram\components\TdJsonClient.js:86:27)
at new Airgram (C:\Users\Oscar Humberto\Desktop\javascript\telenode\node_modules\airgram\Airgram.js:50:116)
at Object. (C:\Users\Oscar Humberto\Desktop\javascript\telenode\src\tdlib.js:6:17)
at Module._compile (node:internal/modules/cjs/loader:1091:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
at Module.load (node:internal/modules/cjs/loader:971:32)
at Function.Module._load (node:internal/modules/cjs/loader:812:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
[nodemon] app crashed - waiting for file changes before starting...

@ymsstudios
Copy link

@xvitaly

@ajai06 reach out to me I have a full fledged react native component working for both android and ios

Hi, I need this too.
How do I reach out?

@vidit-bhatia
Copy link

@ymsstudios @xvitaly I would have to do some work to open source the implementation as I have not added any examples to it.

If you guys are interested and ready to contribute we can work towards taking it out as open source we would need to add test cases and some use case example

@vidit-bhatia
Copy link

@ymsstudios @xvitaly if you guys want I can setup and initial meeting or add a slack or gitter to kick start this

@bemayr
Copy link

bemayr commented Mar 16, 2021

@vidit-bhatia I just did some research regarding react-native and tdlib and stumbled upon this issue. Did you already kick-start anything or have a repo/slack/gitter set up? Your progress sounds awesome! 👏

@zaunermax and me are currently trying to build a minimal RN telegram client and might be able to help to add examples or tests.

@AndrewEyesman
Copy link

Hey @oscar-rey-mosquera sorry for the late response. I honestly can't remember exactly what I did to get it working. Have you tried installing node-gyp?

npm i node-gyp

@vidit-bhatia
Copy link

@bemayr I added you guys a to a gitter workspace to initiate the discussion around this

@rashadg1030
Copy link

rashadg1030 commented Apr 19, 2021

@vidit-bhatia @bemayr Hey guys, I find myself in a similar situation where I need to use TDLib with React Native. Will the approach discussed above work on both Android and iOS? Or only Android?

@bemayr
Copy link

bemayr commented Apr 19, 2021

Hi @rashadg1030, I did not try the solution above yet so sadly I can't say whether it will work or not. But @vidit-bhatia, are there any updates on on your project or gitter.im? Thanks in advance!

@ankitjainhere
Copy link

Hi @vidit-bhatia @bemayr, Can you please show me some example repo, how can I use TDlib in a react-native project?

@bemayr
Copy link

bemayr commented Jun 1, 2021

Hi @ankitjain-1, unfortunately I didn't get any response from @vidit-bhatia and didn't have the time to continue with this project, but if I get back to it, I will ping you 👌

@gaithoben
Copy link

Hey @oscar-rey-mosquera sorry for the late response. I honestly can't remember exactly what I did to get it working. Have you tried installing node-gyp?

npm i node-gyp

Has anyone found out how to make it work?
I have been doing research about this for 24hours and am at a dead end now.
@bemayr

@gaithoben
Copy link

@bemayr I added you guys a to a gitter workspace to initiate the discussion around this

Bring me on board please

@Kylmakalle
Copy link
Contributor

I don't have much experience in React Native, but here's probably what you need to do.

Get compiled TDLib

Link libraries to your native iOS & Android apps

Make sure to have pre-generated ios and android paths with CLI, such as expo run:ios, expo run:android.
Then add TDLib binary as dependency with possible solutions

  • iOS: Locally or SPM or CocoaPods
  • Android: Locally or Gradle or Bazel afaik.

Connect libraries to ReactNative via native modules

wrap TDLib JSON interface, containing only 5 methods in pure C

For async code with td_json_client_send you will probably need to implement Callbacks as described in docs.

Use TDLib in your ReactNative (JS) code

You will get something like this after Native module setup.

const {
  TDLibModule
} = ReactNative.NativeModules;

// Sync code
var client = TDLibModule.td_json_client_create();
var tdlibResponse = TDLibModule.td_json_client_execute(client, {
  "@type": "getTextEntities",
  "text": "@telegram /test_command https://telegram.org telegram.me",
  "@extra": ["5", 7.0, "\\u00e4"]
});
console.log(`Response from TDLib ${tdlibResponse}`);

// Async Code
TDLibModule.td_json_client_send({
    "@type": "setTdlibParameters",
    "parameters": {
      "database_directory": "tdlib",
      "use_message_database": true,
      "use_secret_chats": true,
      "api_id": 94575,
      "api_hash": "a3406de8d171bb422bb6ddf3bbd800e2",
      "system_language_code": "en",
      "device_model": "mobile",
      "application_version": "1.0",
      "enable_storage_optimizer": true
    }
  }
  (jsonResponse) => {
    console.log(`Response from TDLib ${responseJson}`);
  }
);

Well, it's not very trivial, but still possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests