Coder Social home page Coder Social logo

mtproto's People

Contributors

0xflotus avatar anaxita avatar aofei avatar appleboy avatar artem-webdev avatar grinrill avatar hookzof avatar kochetkov-av avatar kulallador avatar luclu7 avatar mikhail-sakhnov avatar mnixry avatar paskal avatar petuhovskiy avatar quenbyako avatar shadowspore avatar vb64 avatar waybackarchiver avatar xakep666 avatar ysx7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mtproto's Issues

[FEAT]: Create updates processing subsystem

Problem description:

Since we have a lot of issues and requests for making utilities to get, handle and process telegram updates, we need to create separate subsystem for it. It must be splitted by specific subsystem. cause some projects doesn't need get updates at all.

Solution:

The idea is to make a separate subpackage that wraps around the telegram.Client itself, very similar to the existing deeplinks package. Perhaps we will be able to make a manager of such updates so as not to load the main components (telegram.Client and mtproto.Client), since not in all cases users need to receive updates.

Possible alternatives:

Leave this problem to end users, but i'm not sure that it's a good solution.

Additional context

Linked issues:

  • #72 updates channel stops exactly after 1 minute after calling cleint.UpdatesGetState
  • multiple requests in our telegram chat

[FEAT]: add support for WebSocket transports

Is your feature request related to a problem? Please describe.

I think if this project can support MTProto connection over WebSocket, it'll be able to solve the blocking problem of some ISPs.

Describe the solution you'd like

For API, maybe we can add a field like WSEndpoint (an HTTP URL string) to the mtproto.Config. If both ServerHost and WSEndpoint have values, WSEndpoint takes precedence.

Describe alternatives you've considered

N/A

Additional context

https://core.telegram.org/mtproto/transports#websocket

https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation

Reducing the number of dependencies

I think a lot of them can be removed:

github.com/xelaj/go-dry (just write if err != nil, and take some cryptographic stuff)
github.com/xelaj/errs (use our own errors)
github.com/pkg/errors (#15)
github.com/willf/pad (easy copy-paste, 10 lines of code)
github.com/vikyd/zero (reflect in runtime just for zero-value check? 😮 )
github.com/iancoleman/strcase (only camel-case func used in codegen, easy copy-paste)
github.com/asaskevich/EventBus (seems it's just unused)

Also we can make the codegen tool as a separate module (so dependencies like jen won't be in the mtproto package itself) done

As the Rob Commander Pike said - A little copying is better than a little dependency

TL Encoder: Option values can be zero, TL Encoder doesn't support it

Copied from #44

@airani wrote:

for example I called this request

res, err := client.MessagesGetHistory(&telegram.MessagesGetHistoryParams{
		Peer: &telegram.InputPeerChannel{
			ChannelId:  channel.TelegramID,
			AccessHash: channel.AccessHash,
		},
		Limit: 100,
                OffsetId: 12,
	})

and I want messages after messageID 12 but this code actually sent OffsetId:12 and OffsetDate:0 and TL priority with OffsetDate and this request not worked correctly!

but with my custom changes that works correctly like this:

type MessagesGetHistoryParams struct {
	Peer        InputPeer
	OffsetId   *int32
	OffsetDate *int32
        // ....
}

func (e *MessagesGetHistoryParams) Encode() []byte {
	err := validator.New().Struct(e)
	dry.PanicIfErr(err)

	buf := serialize.NewEncoder()
	buf.PutUint(e.CRC())
	buf.PutRawBytes(e.Peer.Encode())


        if e.OffsetDate != nil {
                buf.PutInt(*e.OffsetId)
        }
	if e.OffsetDate != nil {
		buf.PutInt(*e.OffsetDate)
	}
        // ...
}

What's the porblem:

Imagine, that we have some method like DoSomethingWithMediaFile(mediaID int, zeroIfYouNeedSave int), where zeroIfYouNeedSave is optional (encoded in bitflags, flag:# in schema)

so, how you can put exact zero value in zeroIfYouNeedSave when if this argument is zero, bitflag set that this option is nil?

TODO:

  • post here list of ALL methods or structs, which are has this situation
  • decide, do we need add this feature to tl parser or just add this methods in methods_specific.go file
  • additional: contact with @levlam, he's knowing more about issues like this one.

[FEAT]: Add chinese readme

What happened:

We suddenly got a lot of traffic to the repository from China. (来自**的朋友大家好!) I don’t know what's happened, but it seems that the number of users of this package from China is approximately equal to the Russian ones.

Maybe we should add a translation? Maybe someone wants to help?

(Need experts) incorrectly decoding for huge messages

So. i made this:

package main

import (
	"github.com/k0kubun/pp"
	"github.com/xelaj/go-dry"
	"github.com/xelaj/mtproto/telegram"
)

func main() {
	client, err := telegram.NewClient(telegram.ClientConfig{
		SessionFile: "/home/me/.local/var/lib/mtproto/session.json",
		ServerHost: "149.154.167.50:443",
		PublicKeysFile: "/home/me/go/src/github.com/xelaj/mtproto/keys/keys.pem",
		AppID: 94575, 
		AppHash: "a3406de8d171bb422bb6ddf3bbd800e2",
	})
	dry.PanicIfErr(err)

	pp.Println(client.MessagesGetAllChats(&telegram.MessagesGetAllChatsParams{ExceptIds:[]int32{}}))
}

Basically, i call messages.getAllChats, and it must return list of chats.

BUT.

It panics for unknown reason!

Decoder is correctly understand, that response of type Chats, chats has one vector param, it has some values, but somwhere decoder decodes wrong.

IF SOMEONE WANT TO DIG THIS ISSUE PLEASE LET ME KNOW

Bug: api methods doesn't generate properly

  • ОС windows 10
  • go version go1.14 windows/amd64

взял пример https://github.com/xelaj/mtproto/tree/master/examples/auth (добавил go.mod)
выполнил go get github.com/xelaj/mtproto, при выполнении go generate github.com/xelaj/mtproto выводится сообщение

go: not generating in packages in dependency modules

при сборки тестового примера получаю такое сообщение

D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\common.go:71:19: undefined: InputClientProxy
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\common.go:72:18: undefined: JSONValue
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\decoder_constructors.go:16:11: undefined: InputGameShortName
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\decoder_constructors.go:18:11: undefined: PageListOrderedItemText
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\decoder_constructors.go:20:11: undefined: UpdateBotInlineSend
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\decoder_constructors.go:22:11: undefined: SecureValueErrorFile
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\functions.go:26:15: undefined: CodeSettings
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\functions.go:43:88: undefined: CodeSettings
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\functions.go:43:104: undefined: AuthSentCode
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\functions.go:82:76: undefined: AuthAuthorization
D:\GoMy\src\pkg\mod\github.com\xelaj\[email protected]\telegram\decoder_constructors.go:22:11: too many errors

Question. How to send media to chat

Please help with an example of sending a photo to an arbitrary chat. Here's what I found myself

client.MessagesSendMedia(&telegram.MessagesSendMediaParams{
	Silent:       false,
	Background:   false,
	ClearDraft:   false,
	Peer:         &telegram.InputPeerUser{ // user data
		UserId:     2121212,
		AccessHash: 212121211221,
	},
	ReplyToMsgId: 0,
	Media:        ???, 
	Message:      "бебе",
	RandomId:     rand.Int63(),
	ReplyMarkup:  nil,
	Entities:     nil,
	ScheduleDate: 0,
})

I don't understand what should be in Media, the field itself is an interface, implementing structure InputMediaUploadedPhoto, it, in turn, has a File property, an interface too, implementing InputFileObj, it's not clear how to fill its properties, I tried it like this:

media, err := client.MakeRequest(&telegram.InputMediaUploadedPhoto{
		File:       &telegram.InputFileObj{
			Id:          rand.Int63(),
			Parts:       -1,
			Name:        "photo_2020-10-24_10-46-53.jpg",
			Md5Checksum: md5,
		},
		Stickers:   nil,
		TtlSeconds: 0,
})

get an error INPUT_METHOD_INVALID_505969924_257016

[BUG]: missing port in dc list

Description

After getting PHONE_MIGRATE_5 err, it would call reconnect with new dc address from dclist, but the format of the ipaddress in dclist is wrong.

in telegram/common.go
func: NewClient
image

image

valid format should like this:
in utils.go
func: defaultDCList
image

Failed snippet

Expected behavior

Additional context

Codegen: need improvements

Current version of codegen for Telegram API is awful. We need to make it more stable and better for reading.

Also, we need to implement somehow auto documentation for types and methods. Looks like JSDoc way is good for us.

This branch is start working on codegen tool

Bad Server salt

After a few minutes of running the client (using the this branch) I get a BadServerSalt error message in the console. After that updates stops coming through even if new messages should come in so it doesn't recover from this error correctly. Sometimes this comes very soon after launch, sometimes it takes 10-20 minutes. Wondering if it's the same issue as in this other mtproto project.

&objects.BadServerSalt{ BadMsgID: 6900221413643567928, BadMsgSeqNo: 1, ErrorCode: 48, NewSalt: -4820136725389948751, } nil

[FEAT]: please add support for receiving media

Is your feature request related to a problem? Please describe.

There is no support of media updates. I'm receiving message of objects.GzipPacked type, which is internal type. 😞

Describe the solution you'd like

I want to receive different types depending on the message (audio, video, document), and content in bytes.

Describe alternatives you've considered

Don't see alternatives.

Additional context

I'm receiving objects.GzipPacked in CustomServerRequestHandler function

Unexpected error!

[]uint8{
  0x00, 0x00, 0x00, 0x00,
} &errors.errorString{
  s: "EOF",
}

I don't know what is this and I don't know why printed in console when program running and then mtproto client not works!
printed in console without any sign for debug! I confused! anyone can help me?

Insecure random bytes generation

Several places are using dry.RandomBytes:

mtproto/aes_ige/aes.go

Lines 102 to 104 in 8c4c69f

dry.RandomBytes(needToAdd)
msg = bytes.Join([][]byte{hash, msg, dry.RandomBytes(needToAdd)}, []byte{})

i.SetBytes(dry.RandomBytes(Int128Len))

And dry.RandomBytes is using math/rand to generate random bytes array.

Maybe dry.RandomBytes should be using crypto/rand, or this package should implement its own method to generate secure random bytes.

[BUG]: tl: structs with not 1st parameter flag parsing incorectly

Description

All telegram api has a few constructors like this one:

poll#86e18161 id:long flags:# closed:flags.0?true public_voters:flags.1?true multiple_choice:flags.2?true quiz:flags.3?true question:string answers:Vector<PollAnswer> close_period:flags.4?int close_date:flags.5?int = Poll;

It generates code like this:

type Poll struct {
	ID             int64
	Closed         bool `tl:"flag:0,encoded_in_bitflags"`
	PublicVoters   bool `tl:"flag:1,encoded_in_bitflags"`
	MultipleChoice bool `tl:"flag:2,encoded_in_bitflags"`
	Quiz           bool `tl:"flag:3,encoded_in_bitflags"`
	Question       string
	Answers        []*PollAnswer
	ClosePeriod    int32 `tl:"flag:4"`
	CloseDate      int32 `tl:"flag:5"`
}

func (*Poll) CRC() uint32 {
	return 0x86e18161
}

func (*Poll) FlagIndex() int {
	return 1
}

See something strange? That's it: flags:# parameter is not first. There are only 2-3 (!!!) constructors like this one, which have flags on second or third position. We provided this goddamn unusual behavior, but decoder wasn't calling FlagIndex method.

Failed snippet

Failed snippet pasted here

Expected behavior

Result must decode correctly!

Notification about go-dry dependency

Since we have a lot of feedback to remove github.com/xelaj/go-dry dependency, we decided to provide a solution how to fix it:

We are working on eitri project, which helps developers to create and deliver amazing cli and web apps, so, really dry method implementations like dry.PanicIfErr are moving to extra.go file in each package.

Also, we're decided to split go-dry package to multiple smaller dry-like packages, which providing problem specific methods, i.e. slicetricks, io readers/writers, maptricks, net helpers, etc.

Getting panic: (*serialize.BadMsgNotification) 0xc0000381c0 [recovered] on Auth example

I'm getting the following error when I try to run the example auth code

panic: (*serialize.BadMsgNotification) 0xc0000381c0 [recovered]
	panic: (*serialize.BadMsgNotification) 0xc0000381c0

goroutine 19 [running]:
github.com/xelaj/mtproto.(*MTProto).recoverGoroutine(0xc0001cc6c0)
	/home/das/go/pkg/mod/github.com/xelaj/[email protected]/mtproto_utils.go:77 +0x125
panic(0x761fe0, 0xc0000381c0)
	/usr/lib/go/src/runtime/panic.go:969 +0x1b9
github.com/xelaj/mtproto.(*MTProto).processResponse(0xc0001cc6c0, 0x5fdb37fd706ac401, 0x0, 0x8425c0, 0xc00010e000, 0xc00010e000, 0x0)
	/home/das/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:350 +0x87e
github.com/xelaj/mtproto.(*MTProto).startReadingResponses.func1(0xc0001cc6c0, 0x842c40, 0xc0001d7dc0)
	/home/das/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:277 +0x296
created by github.com/xelaj/mtproto.(*MTProto).startReadingResponses
	/home/das/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:253 +0x70
exit status 2

What is the possible cause and how do I solve it?

panic in mtproto_utils.go

ОС: Windows 10

I use exemple https://github.com/xelaj/mtproto/tree/master/examples/get_saved_contacts
getting panic

panic: (*serialize.BadMsgNotification) 0xc0004e20e0 [recovered]
	panic: (*serialize.BadMsgNotification) 0xc0004e20e0

goroutine 19 [running]:
github.com/xelaj/mtproto.(*MTProto).recoverGoroutine(0xc000228360)
	C:/Users/Артем/go/pkg/mod/github.com/xelaj/[email protected]/mtproto_utils.go:77 +0x19c
panic(0xf9a9e0, 0xc0004e20e0)
	C:/Go/src/runtime/panic.go:975 +0x4c7
github.com/xelaj/mtproto.(*MTProto).processResponse(0xc000228360, 0x5f93e7b2069a8001, 0x6, 0x103b8a0, 0xc00022a000, 0x0, 0x0)
	C:/Users/Артем/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:316 +0x1307
github.com/xelaj/mtproto.(*MTProto).startReadingResponses.func1(0xc000228360, 0x103bce0, 0xc0002f2fc0)
	C:/Users/Артем/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:243 +0x50b
created by github.com/xelaj/mtproto.(*MTProto).startReadingResponses
	C:/Users/Артем/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:220 +0x5a

callstack:
image

panic occurs when calling various methods in a row, for example, authorization and AccountInitTakeoutSession or AccountInitTakeoutSession and MakeRequestAsSlice, adding Sleep between calls helps

client, err := auth() // method body is taken from here https://github.com/xelaj/mtproto/tree/master/examples/auth
dry.PanicIfErr(err)

//time.Sleep(time.Second)

resp, err := client.AccountInitTakeoutSession(&telegram.AccountInitTakeoutSessionParams{
	Contacts: true,
})
dry.PanicIfErr(err)

Setting ServerHost has no effect

Hi, trying to call AuthSendCode after successfully creating a new client gives me the error: PHONE_MIGRATE_4 (code 303). Indicated in here: https://core.telegram.org/api/errors this is because the account is associated with data center nr 4. Issues is that I've tried all IP addresses that tdlib uses (including nr 4) but none of them work, I get the same error.

Not really sure how to solve this. Is the issue that the specific request need to go to another IP but the client should connect to the standard address given to me when creating the app in the Telegram dev dashboard? Appears that TDlib switches between these endpoints automatically as it has the addresses hard-coded here: https://github.com/tdlib/td/blob/master/td/telegram/net/ConnectionCreator.cpp

Here's the response:

&serialize.RpcResult{ ReqMsgID: 6880960152093058776, Obj: &serialize.RpcError{ ErrorCode: 303, ErrorMessage: "PHONE_MIGRATE_4", }, }

Any suggestions on solutions would be much appreciated.

Need more examples

The lack of descriptions for methods and fields of structures makes it very difficult to work with the code, it is difficult to understand something yourself. Please post more working examples, such as getting a contact list, how to send a message to a specific user, etc., such basic things.

[BUG]: ban phone number during get_updates exaple

Description

I ran get_updates after auth and receive:

&errors.fundamental{ msg: "got nonsystem message from server: *telegram.UpdateShort", stack: &errors.stack{ 0x12bc7fa, 0x12bc33f, 0x12be0b4, 0x106ac41, }, } &telegram.UpdatesTooLong{} &errors.fundamental{ msg: "got nonsystem message from server: *telegram.UpdatesTooLong", stack: &errors.stack{ 0x12bc7fa, 0x12bc33f, 0x12be0b4, 0x106ac41, }, }
Then after few minutes panic: Panicking because of error: The user has been deactivated and banned (code 401)

Checked 2 phone numbers

Code quality: telegram package has much debug stuff

until I figured out the code generation I will describe here

1) there is no point in calling it here

 client.AddCustomServerRequestHandler(client.handleSpecialRequests())

if it makes sense, it still looks like debug prints

 func (c *Client) handleSpecialRequests() func(interface{}) bool {
return func(i interface{}) bool {
	switch msg := i.(type) {
	case *UpdatesObj:
		pp.Println(msg, "UPDATE")
		return true
	case *UpdateShort:
		pp.Println(msg, "SHORT UPDATE")
		return true
	}

	return false
}
  }

2) this piece is like debugging in development

resp, err := client.InvokeWithLayer(ApiVersion, &InitConnectionParams{
	ApiID:          int32(c.AppID),
	DeviceModel:    c.DeviceModel,
	SystemVersion:  c.SystemVersion,
	AppVersion:     c.AppVersion,
	SystemLangCode: "en", // can't be edited, cause docs says that a single possible parameter
	LangCode:       "en",
	Query:          &HelpGetConfigParams{},
})

if err != nil {
	return nil, errors.Wrap(err, "getting server configs")
}

config, ok := resp.(*Config)
if !ok {
	return nil, errors.New("got wrong response: " + reflect.TypeOf(resp).String())
}

pp.Println(config)

3)

PublicKey: publicKeys[0],

Panic when try to UploadSaveBigFilePart

When I do

_, err := client.UploadSaveBigFilePart(&telegram.UploadSaveBigFilePartParams{
	FileId:         somefileid,
	FilePart:       filepart,
	FileTotalParts: total,
	Bytes:          filepartBypes,
})

I always got an error

panic: constructorID '0x997275b5' not found [recovered]
	panic: constructorID '0x997275b5' not found

goroutine 6 [running]:
github.com/xelaj/mtproto.(*MTProto).recoverGoroutine(0xc0002fe000)
	/home/paval/go/pkg/mod/github.com/xelaj/[email protected]/mtproto_utils.go:77 +0x125
panic(0xb7d960, 0xc0002a0180)
	/usr/local/go/src/runtime/panic.go:969 +0x175
github.com/xelaj/mtproto/serialize.(*Decoder).PopObj(0xc0002a0100, 0x5fdbbf3000ed7490, 0xc0002a0120)
	/home/paval/go/pkg/mod/github.com/xelaj/[email protected]/serialize/decoder.go:169 +0x23a
github.com/xelaj/mtproto/serialize.(*RpcResult).DecodeFrom(0xc0002a0120, 0xc0002a0100)
	/home/paval/go/pkg/mod/github.com/xelaj/[email protected]/serialize/common_types.go:279 +0x46
github.com/xelaj/mtproto.(*MTProto).processResponse(0xc0002fe000, 0x5fdbbf3059fc5801, 0x7, 0xe238e0, 0xc0002e6000, 0xc0002e6000, 0x0)
	/home/paval/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:303 +0xbe5
github.com/xelaj/mtproto.(*MTProto).startReadingResponses.func1(0xc0002fe000, 0xe25120, 0xc0002ea180)
	/home/paval/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:277 +0x296
created by github.com/xelaj/mtproto.(*MTProto).startReadingResponses
	/home/paval/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:253 +0x70
exit status 2

[BUG]: Impossible to auth

Description

I've tried the auth example with my own appID and hash
The call of client.AuthSendCode gets stuck/blocked somehow.

When I check the error channel, I've got

decoding received data: Server response error:  (code 4294966892)"

Failed snippet

https://play.golang.org/p/WCtLC1fS8hw

Expected behavior

I expect to receive a Telegram code in order to authenticate

Additional context

I run go version go1.14.3 darwin/amd64

[BUG]: Cant Auth, seems like it's trying to make a IPv6 connection on IPv4 network/internet.

Using https://github.com/xelaj/mtproto/blob/main/examples/auth/main.go to try auth with my app ID and hash returns the floowing error.

marjo@Laptop:~/go/src/bitbucket.org/marjo/telegram/auth$ clear; go run main.go 27xxxxxxxxx
&errors.withStack{
error: &errors.withMessage{
cause: &errors.withStack{
error: &errors.withMessage{
cause: &errors.withStack{
error: &errors.withMessage{
cause: &errors.withStack{
error: &errors.withMessage{
cause: &errors.withStack{
error: &errors.withMessage{
cause: &net.AddrError{
Err: "too many colons in address",
Addr: "2001:067c:04e8:f004:0000:0000:0000:000b",
},
msg: "resolving tcp",
},
stack: &errors.stack{
0x6a7085,
0x6a76c5,
0x6abbb5,
0x6ab9e7,
0x6ac119,
0x6ad585,
0x6abf85,
0x6c9ac5,
0x6c9a29,
0x6e2970,
0x43a136,
0x46caa1,
},
},
msg: "setup connection",
},
stack: &errors.stack{
0x6a788a,
0x6abbb5,
0x6ab9e7,
0x6ac119,
0x6ad585,
0x6abf85,
0x6c9ac5,
0x6c9a29,
0x6e2970,
0x43a136,
0x46caa1,
},
},
msg: "can't connect",
},
stack: &errors.stack{
0x6abc16,
0x6ab9e7,
0x6ac119,
0x6ad585,
0x6abf85,
0x6c9ac5,
0x6c9a29,
0x6e2970,
0x43a136,
0x46caa1,
},
},
msg: "recreating connection",
},
stack: &errors.stack{
0x6ac146,
0x6ad585,
0x6abf85,
0x6c9ac5,
0x6c9a29,
0x6e2970,
0x43a136,
0x46caa1,
},
},
msg: "sending AuthSendCode",
},
stack: &errors.stack{
0x6c9b36,
0x6e2970,
0x43a136,
0x46caa1,
},
}
panic: sending AuthSendCode: recreating connection: can't connect: setup connection: resolving tcp: address 2001:067c:04e8:f004:0000:0000:0000:000b: too many colons in address

goroutine 1 [running]:
main.main()
/home/marjo/go/src/bitbucket.org/marjo/telegram/auth/main.go:70 +0x128b
exit status 2

[BUG]: panic: (*objects.BadMsgNotification)

Description

panic: (*objects.BadMsgNotification) 0xc00058c430 [recovered]
panic: (*objects.BadMsgNotification) 0xc00058c430

goroutine 53 [running]:
github.com/xelaj/mtproto.(*MTProto).recoverGoroutine(0xc000450900)
/Users/vipho/go/pkg/mod/github.com/xelaj/[email protected]/mtproto_utils.go:86 +0x125
panic(0x180dc20, 0xc00058c430)
/usr/local/Cellar/go/1.15.7/libexec/src/runtime/panic.go:969 +0x1b9
github.com/xelaj/mtproto.(*MTProto).processResponse(0xc000450900, 0x1a86fe0, 0xc0000fc070, 0x0, 0x0)
/Users/vipho/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:346 +0x64a
github.com/xelaj/mtproto.(*MTProto).processResponse(0xc000450900, 0x1a86fe0, 0xc0000fc000, 0x88, 0x1a86fe0)
/Users/vipho/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:312 +0x93e
github.com/xelaj/mtproto.(*MTProto).startReadingResponses.func1(0xc000450900, 0x1a89160, 0xc0005ae080)
/Users/vipho/go/pkg/mod/github.com/xelaj/[email protected]/mtproto.go:289 +0x34b
created by github.com/xelaj/mtproto.(*MTProto).startReadingResponses
/:257 +0x70
exit status 2

Is this repo couldn't run on windows?

go run .\main.go
panic: not implemented for windows

goroutine 1 [running]:
github.com/xelaj/go-dry.pathIsWirtable(...)
D:/gopath/src/github.com/abserari/golangbot/vendor/github.com/xelaj/go-dry/path_windows.go:11
github.com/xelaj/go-dry.PathIsWirtable(...)
D:/gopath/src/github.com/abserari/golangbot/vendor/github.com/xelaj/go-dry/path.go:44
github.com/xelaj/mtproto/telegram.NewClient(0x8054c0, 0xe, 0x807247, 0x12, 0x803e67, 0xa, 0x0, 0x0, 0x0, 0x0, ...)
D:/gopath/src/github.com/abserari/golangbot/vendor/github.com/xelaj/mtproto/telegram/common.go:41 +0x172
main.main()
D:/gopath/src/github.com/abserari/golangbot/mtproto/auth_bot/main.go:30 +0x178
exit status 2

[BUG]: getting stuck inside AddCustomServerRequestHandler

i have this very short example of where i want to mark messages as read:

client.AddCustomServerRequestHandler(func(update interface{}) bool {
	switch u := update.(type) {
	case *telegram.UpdateShortMessage:
		peer := &telegram.InputPeerUser{
			UserID:     123,
			AccessHash: 456,
		}

		_, err := client.MessagesReadHistory(peer, u.ID)
		if err != nil {
			panic(err)
		}

		print("here") <----------------
	}

	return false
})

state, err := client.UpdatesGetState()
if err != nil {
	panic(err)
}

the message is being marked as read on the senders device but i am never getting to "here"
so all other subsequent messages are stuck as well because AddCustomServerRequestHandler never returns.

Should remove the panic?

The panic in this code looks like used for debugging. I guess that should remove it?

mtproto/mtproto.go

Lines 364 to 367 in 04ee89d

case *objects.BadMsgNotification:
pp.Println(message)
panic(message) // for debug, looks like this message is important
return BadMsgErrorFromNative(message)

Reconnection doesn't work

Hi,

If you try calling client.Reconnect() after the connection is successful (let's say 30 seconds after connection) the app is unable to reconnect to the Telegram servers. It just hangs... (maybe some mutex or full channel)

Daniel

Codegen: unnecessary strict validation rules for int32 in structs

Let's take this piece of code for example:

mtproto/telegram/methods.go

Lines 3762 to 3771 in b166a10

type MessagesGetHistoryParams struct {
Peer InputPeer `validate:"required"`
OffsetId int32 `validate:"required"`
OffsetDate int32 `validate:"required"`
AddOffset int32 `validate:"required"`
Limit int32 `validate:"required"`
MaxId int32 `validate:"required"`
MinId int32 `validate:"required"`
Hash int32 `validate:"required"`
}

For most of these fields default zero value is totally acceptable. The same goes for most structs.
I believe this should be changed in the generator.

Incorrect git commit message at errors.go:L10

I tried to run my code with the latest version of the library and got this error:

go build
../go/pkg/mod/github.com/xelaj/[email protected]/telegram/common.go:12:2: 
../go/pkg/mod/github.com/xelaj/[email protected]/errors.go:7:1: expected 'STRING', found '<<'
../go/pkg/mod/github.com/xelaj/[email protected]/errors.go:10:9: illegal character U+1F3C7 '🏇'
...
compiler exit status 1

then I went to errors.go (https://github.com/xelaj/mtproto/blob/master/errors.go#L10) and found this there:

import (
	"fmt"
<<<<<<< HEAD
=======
	"strconv"
>>>>>>> 🏇 multiple changes

	"github.com/xelaj/mtproto/serialize"
)

this looks like an incorrect git commit message...

Get PHONE_MIGRATE_5 after sending AuthSendCode

setCode, err := client.AuthSendCode(&telegram.AuthSendCodeParams{
	"+86xxxx", 0000, "0000000", &telegram.CodeSettings{},
})

run auth example and get error msg like this.

panic: Panicking because of error: sedning AuthSendCode: PHONE_MIGRATE_5 (code 303)

Recommend getting latest commit?

Description

The current stable version (v1.0.0), which is the version you get with go get github.com/xelaj/mtproto has various issues that have since been resolved.
For example this issue. Also, some functions like client.IsSessionRegistered(), which exist in the example codes don't exist in the current release. (Typo in the function name btw.).

Proposition

Change the go get command in the README to go get -u github.com/xelaj/mtproto@main as this (with @main) fetches the latest commit. Alternatively you could release a new Release (v1.1.0 ?).
This would've saved me some time.

load session info from memory

hi, seems like session information is hardcoded to be loaded from and saved to file.

would be great if it can come from a string as well.

[BUG]: Recreation Connection fails with IPv6 parsing error

Description

When running in WSL2 (Ubuntu 20.04), upon first request (in my case AuthSendCode) a reconnection is attempted to an invalid address. I'm not exactly sure why that IP is invalid, or where it comes from - presumably it's a telegram DC?

panic: failed AuthSendCode: sending AuthSendCode: recreating connection: can't connect: setup connection: resolving tcp: address 2001:0b28:f23d:f003:0000:0000:0000:000a: too many colons in address

The exact same code works on Windows past this point.
It appears this may be related to the system just having v6 in general - although not sure why it doesn't occur on Windows.

Failed snippet

	config := telegram.ClientConfig{
		SessionFile: sessFile,
		ServerHost: "149.154.167.50:443",
		PublicKeysFile: publicKeys,
		AppID: snip,
		AppHash: "snip",
		InitWarnChannel: true,
	}
	client, err := telegram.NewClient(config)
	signedIn, err := client.IsSessionRegistred()
	setCode, err := client.AuthSendCode(
		phone, int32(config.AppID), config.AppHash, &telegram.CodeSettings{},
	)

Expected behavior

AuthSendCode completes without error

Additional context

Codegen: UNEXPECTEDLY, some Rpc responses are not objects! (see desc)

СукаБлять!

Alright, so some messages like contacts.getSaved response as vector<someType> (which is actually slices). in MTProto vector is LIKELY object (it has 4 bytes for len and bytes stream of wrapped objects).

I changed already decoder of this shit, but we need to fix codegen. Now in MTProto object we have two different request types:

MTProto.MakeRequest(TL) — for REAL objects
MTProto.MakeRequestAsSlice(TL, as reflect.Type) — for responses which is vectors. as need for decoder, it's trying to understand, which type of slice do you need

Need help to investigate how to create MTPROTO keys from usage example

Hello, @ololosha228. Thanks a lot for this library, can you please clarify how I can generate mtproto keys from your example?

func main() {
	keyfile := "/home/r0ck3t/go/src/github.com/xelaj/mtproto/keys/keys.pem"
	TelegramPublicKeys, err := keys.ReadFromFile(keyfile)
	dry.PanicIfErr(err)

I can't figure out how to generate this? Should I use the guide on the official documentation link: https://core.telegram.org/mtproto/auth_key or is there another way to do this? thanks

[FEAT]: add support for context.Context

Is your feature request related to a problem? Please describe.

I think people may prefer to have the ability to cancel their requests at any time.

Describe the solution you'd like

Add context.Context to every func/method that involves network operations.

Describe alternatives you've considered

N/A

Additional context

This isn't a difficult feature to implement. What needs to be considered is the API compatibility (since this module have already released v1.0.0).

Hangs when try to UploadSaveBigFilePart

When I do

_, err := client.UploadSaveBigFilePart(fi, int32(i), int32(totalParts), part)
if err != nil {
	panic(err)
}

it just hands with message in log

nil &errors.withStack{
  error: &errors.withMessage{
    cause: &errors.withStack{
      error: &errors.withMessage{
        cause: &errors.withStack{
          error: &errors.withMessage{
            cause: &errors.withStack{
              error: &errors.withMessage{
                cause: tl.ErrRegisteredObjectNotFound{
                  Crc:  0x997275b5,
                  Data: []uint8{},
                },
                msg: "decode interface",
              },
              stack: &errors.stack{
                0x93ddd6,
                0x93d05b,
                0x93e7d0,
                0x93ca5d,
                0x95baa5,
                0x95f150,
                0x46bbe1,
              },
            },
            msg: "decode field 'Obj'",
          },
          stack: &errors.stack{
            0x93d16a,
            0x93e7d0,
            0x93ca5d,
            0x95baa5,
            0x95f150,
            0x46bbe1,
          },
        },
        msg: "decode registered object *objects.RpcResult",
      },
      stack: &errors.stack{
        0x93e84b,
        0x93ca5d,
        0x95baa5,
        0x95f150,
        0x46bbe1,
      },
    },
    msg: "decoding predicted object",
  },
  stack: &errors.stack{
    0x93ca9c,
    0x95baa5,
    0x95f150,
    0x46bbe1,
  },

I use https://github.com/xelaj/mtproto/tree/new_decoder_refactoring
Based on

cause: tl.ErrRegisteredObjectNotFound{
  Crc:  0x997275b5,
  Data: []uint8{},
},

I assume I have same problem here as in #50

misprint[BUG]:

Если поставить пакет через go get то там в telegram/common.go и паре примеров опечатка.
Вместо PathIsWritable будет PathIsWirtable

update to latest layer 129

when trying to update to the latest layer 129 i am getting an error about PseudoBool not found.

any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.