终止支持通知: AWS 将于 2026 年 10 月 30 日终止对亚马逊 Pinpoint 的支持。2026 年 10 月 30 日之后,您将不再能够访问 Amazon Pinpoint 控制台或 Amazon Pinpoint 资源(端点、分段、活动、旅程和分析)。有关更多信息,请参阅 Amazon Pinpoint 终止支持。注意: APIs 与短信相关、语音、移动推送、OTP 和电话号码验证不受此更改的影响,并受 AWS 最终用户消息的支持。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Amazon Pinpoint 以编程方式检索端点的应用程序内消息
您的应用程序可以调用 GetInAppMessagesAPI 来检索给定端点有权接收的所有应用内消息。在调用 GetInAppMessages API 时,您需要提供以下参数:
当您使用这些值调用 API 时,它会返回一个消息列表。有关此操作生成的响应的更多信息,请参阅GetInAppMessages Amazon Pinpoint API 响应 JSON 示例。
您可以使用 AWS SDKs 来调用该GetInAppMessages操作。以下代码示例包括检索应用程序内消息的函数。
- JavaScript
-
在单独的模块中创建客户端并将其导出:
import { PinpointClient } from "@aws-sdk/client-pinpoint";
const REGION = "us-east-1";
const pinClient = new PinpointClient({ region: REGION });
export { pinClient };
检索端点的应用程序内消息:
// Import required AWS SDK clients and commands for Node.js
import { PinpointClient, GetInAppMessagesCommand } from "@aws-sdk/client-pinpoint";
import { pinClient } from "./lib/pinClient.js";
("use strict");
//The Amazon Pinpoint application ID.
const projectId = "4c545b28d21a490cb51b0b364example";
//The ID of the endpoint to retrieve messages for.
const endpointId = "c5ac671ef67ee3ad164cf7706example";
const params = {
ApplicationId: projectId,
EndpointId: endpointId
};
const run = async () => {
try {
const data = await pinClient.send(new GetInAppMessagesCommand(params));
console.log(JSON.stringify(data, null, 4));
return data;
} catch (err) {
console.log("Error", err);
}
};
run();
- Python
-
import logging
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
def retrieve_inapp_messages(
pinpoint_client, project_id, endpoint_id):
"""
Retrieves the in-app messages that a given endpoint is entitled to.
:param pinpoint_client: A Boto3 Pinpoint client.
:param project_id: An Amazon Pinpoint project ID.
:param endpoint_id: The ID of the endpoint to retrieve messages for.
:return: A JSON object that contains information about the in-app message.
"""
try:
response = pinpoint_client.get_in_app_messages(
ApplicationId=project_id,
EndpointId=endpoint_id)
except ClientError:
logger.exception("Couldn't retrieve messages.")
raise
else:
return response
def main():
project_id = "4c545b28d21a490cb51b0b364example"
endpoint_id = "c5ac671ef67ee3ad164cf7706example"
inapp_response = retrieve_inapp_messages(
boto3.client('pinpoint'), project_id, endpoint_id)
print(inapp_response)
if __name__ == '__main__':
main()