tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

How to send a story as the current user? #3002

Closed wudb closed 3 months ago

wudb commented 3 months ago

I use sendStory to send the story, but when the chat id is passed into my own id, an error is reported: “Chat not found”, please help me, thank you.

code show as below:

final input = td.InputStoryContentPhoto( photo: td.InputFileLocal(path: path), addedStickerFileIds: []); final result = await client.send(td.SendStory( chatId: me.id, content: input, privacySettings: const td.StoryPrivacySettingsEveryone(exceptUserIds: []), activePeriod: 86400, fromStoryFullId: null, isPostedToChatPage: true, protectContent: false, ));

levlam commented 3 months ago

You must pass a chat identifier, but passing a user identifier. You need to create the chat with self (Saved Messages) first by calling createPrivateChat, receive its identifier, and then use the identifier.

wudb commented 3 months ago

thanks! So how do I judge whether I can send a story? Because some users can choose chat, and when some users cannot choose, they need to createPrivateChat?

levlam commented 3 months ago

Use getChatsToSendStories and canSendStory.

wudb commented 3 months ago

Thanks! Telegram app does not need to have a chat before it can send story. Why does tdlib need to have a chat before it can send story?

wudb commented 3 months ago

I encountered this error when forwarding the story: Can't use file of type PhotoStory as Photo. code:

Future<bool> forwardStory(int chatId, td.Story story) async {
    if (client != null && story.canBeForwarded) {
      td.InputStoryContent? input;
      if (story.content is td.StoryContentPhoto) {
        final content = story.content as td.StoryContentPhoto;
        final photo = content.photo.sizes.last;
        input = td.InputStoryContentPhoto(photo: td.InputFileRemote(id: photo.photo.remote.id), addedStickerFileIds: const []);
      } else if (story.content is td.StoryContentVideo) {
        final content = story.content as td.StoryContentVideo;
        final video = content.video.video;
        input = td.InputStoryContentVideo(video: td.InputFileRemote(id: video.remote.id),
            addedStickerFileIds: const [],
            duration: content.video.duration,
            isAnimation: content.video.isAnimation
        );
      }
      if (input != null) {
        final result = await client!.send(td.SendStory(
          chatId: chatId,
          content: input,
          caption: story.caption,
          privacySettings: const td.StoryPrivacySettingsEveryone(exceptUserIds: []),
          activePeriod: 86400,
          fromStoryFullId: td.StoryFullId(senderChatId: story.senderChatId, storyId: story.id),
          isPostedToChatPage: true,
          protectContent: false,
        ));
        Log.d("TG | forwardStory result: ${result.toJson()}");
        return result is td.Story;
      }
    }
    return false;
  }

please help me, thanks!

wudb commented 3 months ago

When I call the above method to forward the video story, I pass in the chatId created by createPrivateChat and the sending is successful, but I cannot see the story I forwarded on my wall.

levlam commented 3 months ago

All Telegram apps works in exactly the same way as TDLib.

wudb commented 3 months ago

All Telegram apps works in exactly the same way as TDLib.

now, I can use createPrivateChat to send stories. The sending is successful, but I cannot see the story on the app. The code is as above.

levlam commented 3 months ago

Then, you didn't send the story. Did you wait for updateStory with story.is_being_sent being false?

wudb commented 3 months ago
image

story.is_being_sent is true, But I can’t see the story I posted on the telegram app.

levlam commented 3 months ago

You definitely must not see in other apps a story that isn't sent yet.

wudb commented 3 months ago

The sendStory shows success, and the is_being_sent in updateStory also shows success. Where does it indicate that the story was not sent successfully?

levlam commented 3 months ago

is_being_sent shows that the story is being sent.

wudb commented 3 months ago

thanks! It's ok, caption is too long.