Communication difficulties between Telegram and Lambda in Java

I successfully created my first Telegram bot and connected it via webhook to a public API exposed using AWS API Gateway that triggers a lambda written in Java 8.

I verified the connection using CloudWatch, sending a message to the bot and receiving a log written in the lambda.

My problem lies in the lambda code, because although the communication works, it contains information that I believe is wrong.

Let me explain:

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class App implements RequestHandler<Object, Object> {

    @Override
    public Object handleRequest(Object update, Context context) {

        context.getLogger().log("Object: " + update);

        return 0
    }
}

This is the simple Lambda content that allowed me to get this log:

"Object":{
   version=1.0,
   "resource=/javatest",
   "path=/default/javatest",
   "httpMethod=POST",
   "headers="{
      Content-Length=273,
      "Content-Type=application/json",
      Host=odd9kjkana.execute-api.eu-west-1.amazonaws.com,
      X-Amzn-Trace-Id=Root=1-663158ad-585f95f7491168214c543f33,
      X-Forwarded-For=91.108.6.96,
      X-Forwarded-Port=443,
      "X-Forwarded-Proto=https",
      "accept-encoding=gzip",
      "deflate"
   },
   "multiValueHeaders="{
      "Content-Length="[
         273
      ],
      "Content-Type="[
         "application/json"
      ],
      "Host="[
         odd9kjiaoa.execute-api.eu-west-1.amazonaws.com
      ],
      "X-Amzn-Trace-Id="[
         Root=1-663158ad-585f95f7491168214c543f33
      ],
      "X-Forwarded-For="[
         91.108.6.96
      ],
      "X-Forwarded-Port="[
         443
      ],
      "X-Forwarded-Proto="[
         "https"
      ],
      "accept-encoding="[
         "gzip",
         "deflate"
      ]
   },
   "queryStringParameters=null",
   "multiValueQueryStringParameters=null",
   "requestContext="{
      accountId=891370093172,
      apiId=odd9kjkana,
      domainName=odd9kjkana.execute-api.eu-west-1.amazonaws.com,
      domainPrefix=odd9kjkana,
      extendedRequestId=XDrLLhT4DoEEPSg=,
      "httpMethod=POST",
      "identity="{
         "accessKey=null",
         "accountId=null",
         "caller=null",
         "cognitoAmr=null",
         "cognitoAuthenticationProvider=null",
         "cognitoAuthenticationType=null",
         "cognitoIdentityId=null",
         "cognitoIdentityPoolId=null",
         "principalOrgId=null",
         sourceIp=91.108.6.96,
         "user=null",
         "userAgent=",
         "userArn=null"
      },
      "path=/default/javatest",
      protocol=HTTP/1.1,
      requestId=XDrLLhT4DoEEPSg=,
      "requestTime=30/Apr/2024":"20":"46":37 +0000,
      requestTimeEpoch=1714509997602,
      "resourceId=ANY /javatest",
      "resourcePath=/javatest",
      "stage=default"
   },
   "pathParameters=null",
   "stageVariables=null",
   "body="{
      "update_id":879419474,
      "message":{
         "message_id":107,
         "from":{
            "id":177801168,
            "is_bot":false,
            "first_name":"Legolas",
            "username":"Sl1me",
            "language_code":"it"
         },
         "chat":{
            "id":177801168,
            "first_name":"Legolas",
            "username":"Sl1me",
            "type":"private"
         },
         "date":1714507808,
         "text":"Test37"
      }
   },
   isBase64Encoded=false
}

While the message I had sent was very different, that ‘Test37’ found was from a few days ago.

That said, once I understand the correct structure obviously I will have to try to correctly deserialize the object sent by Telegram, for now I need to understand why it returns me an old message and what is the structure I should expect so that I can build the appropriate supporting classes.

Just for completeness, by directly calling the bot via polling (https://api.telegram.org/bot{MY_TOKEN}/getUpdates?offset=-1) I get the result I am looking for, but precisely I want to use webhooks.

I’m trying to consult this guide, but I can’t find the problem.

I hope you can help me. Thank you

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật