Telnyx Twexit API客户端
twexit的Python项目详细描述
Telnyx“Twexit”Python库
Telnyx“Twexit”Python库允许用户发送消息和验证webhook,只需对现有Twilio消息传递代码进行最小的更改。在
安装
此SDK可以通过pip
安装:
pip install twexit
或者从源代码直接下载并解压存储库,然后从twexit-python
文件夹中运行
帐户设置
- 在
完成Portal Setup以设置启用消息的号码。在
在 - 在
按照附加的Twexit setup steps配置webhook
在
使用
发送消息
fromtwilio.restimportClient# Your organization ID fromaccount_sid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"# An API key from https://portal.telnyx.com/#/app/api-keysauth_token="KEY0123456789xxxxx"message=client.messages.create(to="+13125550123",from_="+16165550123",body="Free yourself with Twexit!")print(message.sid)
Webhook验证
Twexit使用了快速的非对称签名算法Ed25519,以避免在SHA-1中发现问题。要从HMAC-SHA1签名方法切换,请执行以下步骤:
- 在 在
- 在
更新应用程序以使用
在TwexitRequestValidator
而不是RequestValidator
- 在
从请求中提取
在X-Twexit-Signature
,并在调用验证器时提供它。在
fromtwilio.request_validatorimportTwexitRequestValidatorpublic_key="abcdef123456xxxxx"validator=TwexitRequestValidator(public_key)url='https://mycompany.com/myapp.php?foo=1&bar=2'params={"MessageSid":"CA1234567890ABCDE","ApiVersion":"2010-04-01","Body":"Aloha!","From":"+13125550123","To":"+16165550123",}# The X-Twexit-Signature header attached to the requesttwexit_signature='0/KCTR6DLpKmkAf8muzZqo1nDgQ='print(validator.validate(url,params,twexit_signature))
注意事项
这个SDK目前只提供通过REST发送消息和在接收消息时验证webhook的功能。尚不支持消息传递产品和其他产品(语音、传真)的配置。在
- 项目
标签: