-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1110b60
commit 7cb4bfb
Showing
20 changed files
with
954 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .app import Twilio | ||
|
||
__all__ = ['Twilio'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from twilio.rest import Client | ||
|
||
from npi.core.app import App, npi_tool | ||
from npi.config import config | ||
|
||
from npi.app.twilio.schema import * | ||
|
||
|
||
class Twilio(App): | ||
def __init__(self): | ||
super().__init__( | ||
name='twilio', | ||
description='Send messages using Twilio, e.g., twilio("send a message to +16507055795")', | ||
system_role='You are a Twilio Agent can send messages via WhatsApp or SMS', | ||
) | ||
|
||
cred = config.get_twilio_credentials() | ||
self.client = Client(cred.account_sid, cred.auth_token) | ||
self.from_number = cred.from_phone_number | ||
|
||
@npi_tool(description='Send a sms message to a phone number') | ||
async def send_sms_message(self, params: MessageParameters): | ||
message = self.client.messages.create( | ||
from_=f'{self.from_number}', | ||
body=params.message, | ||
to=f"{params.to}", | ||
) | ||
|
||
return f'Message has been successfully sent, sid: {message.sid}' | ||
|
||
@npi_tool(description='Send a whatsapp message to a phone number') | ||
async def send_whatsapp_message(self, params: MessageParameters): | ||
message = self.client.messages.create( | ||
from_=f'whatsapp:{self.from_number}', | ||
body=params.message, | ||
to=f"whatsapp:{params.to}", | ||
) | ||
|
||
return f'Message has been successfully sent, sid: {message.sid}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import Field | ||
from npi.types import Parameters | ||
|
||
|
||
class MessageParameters(Parameters): | ||
to: str = Field(default=None, description='the phone number you want to send the message to') | ||
message: str = Field(default=100, description='the message body you want to send') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.