Skip to content

Commit

Permalink
Bug FIxes, Add example for group call
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Apr 16, 2024
1 parent 110a93b commit d0dd0a3
Show file tree
Hide file tree
Showing 7 changed files with 713 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ client.AddInlineHandler("<pattern>", func(iq *telegram.InlineQuery) error {
- [x] MessageMediaPoll, UserFull Decode Fails
- [x] invokeWithLayer channel missing while bad Salt
- [x] tcp.io.Reader.Read unstable
- [ ] Session File some issues
- [ ] Unidentified RPCError decoding fails
- [ ] HTML Parser

## Contributing
Expand Down
34 changes: 34 additions & 0 deletions examples/tgcalls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div align="center">
<h1>Telegram Group Calls Example</h1>
</div>

## TGCalls

> A demonstration of Telegram Group Calls with gogram using [NtgCalls](https://github.com/pytgcalls/ntgcalls) core.
### Get Started

To get started, download the latest Shared Libraries:
- [libtgcalls.so](https://envs.sh/tsh.so) (for Unix-based systems)
- [libtgcalls.dll](https://envs.sh/tsd.dll) (for Windows)
- [Builds](https://github.com/pytgcalls/ntgcalls/releases) (for other platforms)

Copy the downloaded Shared Library to the root directory of this example folder.

Download the header file:
- [tgcalls.h](https://envs.sh/ts2.h)

Copy the downloaded header file to the root directory of this example folder.

```bash

### Running the Example

```bash
go run .
```

### Credits

- [NTGCalls](https://github.com/pytgcalls/ntgcalls)

93 changes: 93 additions & 0 deletions examples/tgcalls/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package examples

//#cgo LDFLAGS: -L . -lntgcalls -Wl,-rpath=./
import "C"
import (
"fmt"

"github.com/amarnathcjd/gogram/telegram"
)

// media.Video = &VideoDescription{
// InputMode: InputModeShell,
// Input: fmt.Sprintf("ffmpeg -i %s -loglevel panic -f rawvideo -r 24 -pix_fmt yuv420p -vf scale=1280:720 pipe:1", video),
// Width: 1280,
// Height: 720,
// Fps: 24,
// }

func main() {
client, err := telegram.NewClient(telegram.ClientConfig{
AppID: 6,
AppHash: "<app_hash>",
})

client.AuthPrompt() // client.Login("<phone_number>")

if err != nil {
panic(err)
}

ntg := NTgCalls()
defer ntg.Free()

url := "https://envs.sh/trq.m4a" // audio file url

media := MediaDescription{
Audio: &AudioDescription{
InputMode: InputModeShell,
SampleRate: 128000,
BitsPerSample: 16,
ChannelCount: 2,
Input: fmt.Sprintf("ffmpeg -i %s -loglevel panic -f s16le -ac 2 -ar 128k pipe:1", url), // ffmpeg command to convert audio to s16le format and pipe it to stdout
},
}

joinGroupCall(client, ntg, "@rosexchat", media)

client.Idle()
}

// join groupcall and start streaming audio
func joinGroupCall(client *telegram.Client, ntg *Client, chatId interface{}, media MediaDescription) {
me, _ := client.GetMe() // get the current user for JoinAs

call, err := client.GetGroupCall(chatId) // get the group call object
if err != nil {
panic(err)
}

rawChannel, _ := client.GetSendablePeer(chatId)
channel := rawChannel.(*telegram.InputPeerChannel)
jsonParams, err := ntg.CreateCall(channel.ChannelID, media) // create call object with media description
if err != nil {
panic(err)
}

callResRaw, err := client.PhoneJoinGroupCall(
&telegram.PhoneJoinGroupCallParams{
Muted: false,
VideoStopped: true, // false for video call
Call: call,
Params: &telegram.DataJson{
Data: jsonParams,
},
JoinAs: &telegram.InputPeerUser{
UserID: me.ID,
AccessHash: me.AccessHash,
},
},
)

if err != nil {
panic(err)
}

callRes := callResRaw.(*telegram.UpdatesObj)
for _, update := range callRes.Updates {
switch u := update.(type) {
case *telegram.UpdateGroupCallConnection: // wait for connection params
_ = ntg.Connect(channel.ChannelID, u.Params.Data)
}
}
}
Loading

0 comments on commit d0dd0a3

Please sign in to comment.